This source file includes following definitions.
- ExecuteCalculateDrawProperties
- ClearDamageForAllSurfaces
- EmulateDrawingOneFrame
- CreateTestTreeWithOneSurface
- CreateTestTreeWithTwoSurfaces
- CreateAndSetUpTestTreeWithOneSurface
- CreateAndSetUpTestTreeWithTwoSurfaces
- 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
#include "cc/trees/damage_tracker.h"
#include "cc/base/math_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/output/filter_operation.h"
#include "cc/output/filter_operations.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/effects/SkBlurImageFilter.h"
#include "ui/gfx/quad_f.h"
namespace cc {
namespace {
void ExecuteCalculateDrawProperties(LayerImpl* root,
LayerImplList& render_surface_layer_list) {
ASSERT_TRUE(root->render_surface());
ASSERT_FALSE(render_surface_layer_list.size());
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root, root->bounds(), &render_surface_layer_list);
LayerTreeHostCommon::CalculateDrawProperties(&inputs);
}
void ClearDamageForAllSurfaces(LayerImpl* layer) {
if (layer->render_surface())
layer->render_surface()->damage_tracker()->DidDrawDamagedArea();
for (size_t i = 0; i < layer->children().size(); ++i)
ClearDamageForAllSurfaces(layer->children()[i]);
}
void EmulateDrawingOneFrame(LayerImpl* root) {
LayerImplList render_surface_layer_list;
ExecuteCalculateDrawProperties(root, render_surface_layer_list);
for (int i = render_surface_layer_list.size() - 1; i >= 0; --i) {
RenderSurfaceImpl* target_surface =
render_surface_layer_list[i]->render_surface();
target_surface->damage_tracker()->UpdateDamageTrackingState(
target_surface->layer_list(),
target_surface->OwningLayerId(),
target_surface->SurfacePropertyChangedOnlyFromDescendant(),
target_surface->content_rect(),
render_surface_layer_list[i]->mask_layer(),
render_surface_layer_list[i]->filters());
}
root->ResetAllChangeTrackingForSubtree();
}
class DamageTrackerTest : public testing::Test {
public:
DamageTrackerTest() : host_impl_(&proxy_, &shared_bitmap_manager_) {}
scoped_ptr<LayerImpl> CreateTestTreeWithOneSurface() {
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_.active_tree(), 1);
scoped_ptr<LayerImpl> child =
LayerImpl::Create(host_impl_.active_tree(), 2);
root->SetPosition(gfx::PointF());
root->SetAnchorPoint(gfx::PointF());
root->SetBounds(gfx::Size(500, 500));
root->SetContentBounds(gfx::Size(500, 500));
root->SetDrawsContent(true);
root->CreateRenderSurface();
root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500));
child->SetPosition(gfx::PointF(100.f, 100.f));
child->SetAnchorPoint(gfx::PointF());
child->SetBounds(gfx::Size(30, 30));
child->SetContentBounds(gfx::Size(30, 30));
child->SetDrawsContent(true);
root->AddChild(child.Pass());
return root.Pass();
}
scoped_ptr<LayerImpl> CreateTestTreeWithTwoSurfaces() {
scoped_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_.active_tree(), 1);
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);
scoped_ptr<LayerImpl> grand_child2 =
LayerImpl::Create(host_impl_.active_tree(), 5);
root->SetPosition(gfx::PointF());
root->SetAnchorPoint(gfx::PointF());
root->SetBounds(gfx::Size(500, 500));
root->SetContentBounds(gfx::Size(500, 500));
root->SetDrawsContent(true);
root->CreateRenderSurface();
root->render_surface()->SetContentRect(gfx::Rect(0, 0, 500, 500));
child1->SetPosition(gfx::PointF(100.f, 100.f));
child1->SetAnchorPoint(gfx::PointF());
child1->SetBounds(gfx::Size(30, 30));
child1->SetContentBounds(gfx::Size(30, 30));
child1->SetOpacity(0.5f);
child1->SetDrawsContent(false);
child1->SetForceRenderSurface(true);
child2->SetPosition(gfx::PointF(11.f, 11.f));
child2->SetAnchorPoint(gfx::PointF());
child2->SetBounds(gfx::Size(18, 18));
child2->SetContentBounds(gfx::Size(18, 18));
child2->SetDrawsContent(true);
grand_child1->SetPosition(gfx::PointF(200.f, 200.f));
grand_child1->SetAnchorPoint(gfx::PointF());
grand_child1->SetBounds(gfx::Size(6, 8));
grand_child1->SetContentBounds(gfx::Size(6, 8));
grand_child1->SetDrawsContent(true);
grand_child2->SetPosition(gfx::PointF(190.f, 190.f));
grand_child2->SetAnchorPoint(gfx::PointF());
grand_child2->SetBounds(gfx::Size(6, 8));
grand_child2->SetContentBounds(gfx::Size(6, 8));
grand_child2->SetDrawsContent(true);
child1->AddChild(grand_child1.Pass());
child1->AddChild(grand_child2.Pass());
root->AddChild(child1.Pass());
root->AddChild(child2.Pass());
return root.Pass();
}
scoped_ptr<LayerImpl> CreateAndSetUpTestTreeWithOneSurface() {
scoped_ptr<LayerImpl> root = CreateTestTreeWithOneSurface();
EmulateDrawingOneFrame(root.get());
return root.Pass();
}
scoped_ptr<LayerImpl> CreateAndSetUpTestTreeWithTwoSurfaces() {
scoped_ptr<LayerImpl> root = CreateTestTreeWithTwoSurfaces();
EmulateDrawingOneFrame(root.get());
return root.Pass();
}
protected:
FakeImplProxy proxy_;
TestSharedBitmapManager shared_bitmap_manager_;
FakeLayerTreeHostImpl host_impl_;
};
TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
EXPECT_EQ(2u, root->render_surface()->layer_list().size());
EXPECT_EQ(1, root->render_surface()->layer_list()[0]->id());
EXPECT_EQ(2, root->render_surface()->layer_list()[1]->id());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 500.f, 500.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* child2 = root->children()[1];
gfx::RectF child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
ASSERT_TRUE(child1->render_surface());
EXPECT_FALSE(child2->render_surface());
EXPECT_EQ(3u, root->render_surface()->layer_list().size());
EXPECT_EQ(2u, child1->render_surface()->layer_list().size());
EXPECT_FLOAT_RECT_EQ(gfx::RectF(190.f, 190.f, 16.f, 18.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 500.f, 500.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(110.f, 111.f, 12.f, 13.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(110.f, 111.f, 12.f, 13.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(20.f, 25.f, 1.f, 2.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(120.f, 125.f, 1.f, 2.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(10.f, 11.f, 12.f, 13.f));
child->SetOpacity(0.5f);
EmulateDrawingOneFrame(root.get());
ASSERT_FALSE(child->render_surface());
ASSERT_EQ(2u, root->render_surface()->layer_list().size());
gfx::RectF expected_rect = gfx::RectF(100.f, 100.f, 30.f, 30.f);
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(root_damage_rect.IsEmpty());
ClearDamageForAllSurfaces(root.get());
child->SetPosition(gfx::PointF(200.f, 230.f));
EmulateDrawingOneFrame(root.get());
expected_rect.Union(gfx::RectF(200, 230, 30, 30));
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
gfx::Transform rotation;
rotation.Rotate(45.0);
ClearDamageForAllSurfaces(root.get());
child->SetAnchorPoint(gfx::PointF(0.5f, 0.5f));
child->SetPosition(gfx::PointF(85.f, 85.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(85.f, 85.f, 45.f, 45.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
child->SetTransform(rotation);
EmulateDrawingOneFrame(root.get());
float expected_width = 30.f * sqrt(2.f);
float expected_position = 100.f - 0.5f * expected_width;
gfx::RectF expected_rect(
expected_position, expected_position, expected_width, expected_width);
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
gfx::Transform transform;
transform.Translate3d(500.0, 500.0, 0.0);
transform.ApplyPerspectiveDepth(1.0);
transform.RotateAboutYAxis(45.0);
transform.Translate3d(-50.0, -50.0, 0.0);
child->SetPosition(gfx::PointF(0.f, 0.f));
child->SetBounds(gfx::Size(100, 100));
child->SetContentBounds(gfx::Size(100, 100));
child->SetTransform(transform);
EmulateDrawingOneFrame(root.get());
gfx::QuadF test_quad(gfx::RectF(gfx::PointF(), gfx::SizeF(100.f, 100.f)));
bool clipped = false;
MathUtil::MapQuad(transform, test_quad, &clipped);
EXPECT_TRUE(clipped);
ClearDamageForAllSurfaces(root.get());
child->SetOpacity(0.5f);
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
gfx::RectF damage_we_care_about =
gfx::RectF(gfx::PointF(), gfx::SizeF(500.f, 500.f));
EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
}
TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* surface = root->children()[0];
LayerImpl* child = surface->children()[0];
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(5.f));
int outset_top, outset_right, outset_bottom, outset_left;
filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
ClearDamageForAllSurfaces(root.get());
surface->SetFilters(filters);
EmulateDrawingOneFrame(root.get());
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(1.f, 2.f, 3.f, 4.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
gfx::RectF expected_damage_rect =
gfx::RectF(301.f, 302.f, 3.f, 4.f);
expected_damage_rect.Inset(-outset_left,
-outset_top,
-outset_right,
-outset_bottom);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
gfx::RectF root_damage_rect, child_damage_rect;
child->SetDrawsContent(true);
skia::RefPtr<SkImageFilter> filter =
skia::AdoptRef(new SkBlurImageFilter(SkIntToScalar(2),
SkIntToScalar(2)));
FilterOperations filters;
filters.Append(FilterOperation::CreateReferenceFilter(filter));
ClearDamageForAllSurfaces(root.get());
child->SetFilters(filters);
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(100.f, 100.f, 30.f, 30.f), root_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 30.f, 30.f), child_damage_rect);
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(0.f, 0.f, 1.f, 1.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(100.f, 100.f, 30.f, 30.f), root_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 30.f, 30.f), child_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* child2 = root->children()[1];
child1->SetDrawsContent(true);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(2.f));
int outset_top, outset_right, outset_bottom, outset_left;
filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
ClearDamageForAllSurfaces(root.get());
child1->SetBackgroundFilters(filters);
EmulateDrawingOneFrame(root.get());
ClearDamageForAllSurfaces(root.get());
root->SetUpdateRect(gfx::RectF(297.f, 297.f, 2.f, 2.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
gfx::RectF expected_damage_rect =
gfx::RectF(297.f, 297.f, 2.f, 2.f);
expected_damage_rect.Inset(-outset_left,
-outset_top,
-outset_right,
-outset_bottom);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
root->SetUpdateRect(gfx::RectF(297.f, 297.f, 30.f, 30.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
expected_damage_rect =
gfx::RectF(297.f, 297.f, 30.f, 30.f);
expected_damage_rect.Inset(-outset_left,
-outset_top,
0,
0);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
root->SetUpdateRect(gfx::RectF(30.f, 30.f, 2.f, 2.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
expected_damage_rect =
gfx::RectF(30.f, 30.f, 2.f, 2.f);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
root->SetUpdateRect(gfx::RectF(99.f, 99.f, 1.f, 1.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
expected_damage_rect =
gfx::RectF(99.f, 99.f, 1.f, 1.f);
expected_damage_rect.Inset(-outset_left + 1,
-outset_top + 1,
-outset_right,
-outset_bottom);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
child2->SetUpdateRect(gfx::RectF(0.f, 0.f, 1.f, 1.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
expected_damage_rect =
gfx::RectF(11.f, 11.f, 1.f, 1.f);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
ClearDamageForAllSurfaces(root.get());
child1->SetUpdateRect(gfx::RectF(0.f, 0.f, 1.f, 1.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
expected_damage_rect =
gfx::RectF(100.f, 100.f, 1.f, 1.f);
expected_damage_rect.Inset(-outset_left,
-outset_top,
-outset_right,
-outset_bottom);
EXPECT_FLOAT_RECT_EQ(expected_damage_rect, root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child1 = root->children()[0];
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl_.active_tree(), 3);
child2->SetPosition(gfx::PointF(400.f, 380.f));
child2->SetAnchorPoint(gfx::PointF());
child2->SetBounds(gfx::Size(6, 8));
child2->SetContentBounds(gfx::Size(6, 8));
child2->SetDrawsContent(true);
root->AddChild(child2.Pass());
}
EmulateDrawingOneFrame(root.get());
ASSERT_EQ(3u, root->render_surface()->layer_list().size());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(400.f, 380.f, 6.f, 8.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(root_damage_rect.IsEmpty());
root->RemoveChild(child1);
child1 = NULL;
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(100.f, 100.f, 30.f, 30.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl_.active_tree(), 3);
child2->SetPosition(gfx::PointF(400.f, 380.f));
child2->SetAnchorPoint(gfx::PointF());
child2->SetBounds(gfx::Size(6, 8));
child2->SetContentBounds(gfx::Size(6, 8));
child2->SetDrawsContent(true);
child2->ResetAllChangeTrackingForSubtree();
ASSERT_FALSE(child2->LayerPropertyChanged());
ASSERT_TRUE(child2->update_rect().IsEmpty());
root->AddChild(child2.Pass());
}
EmulateDrawingOneFrame(root.get());
ASSERT_EQ(3u, root->render_surface()->layer_list().size());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(400.f, 380.f, 6.f, 8.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child1 = root->children()[0];
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl_.active_tree(), 3);
child2->SetPosition(gfx::PointF(400.f, 380.f));
child2->SetAnchorPoint(gfx::PointF());
child2->SetBounds(gfx::Size(6, 8));
child2->SetContentBounds(gfx::Size(6, 8));
child2->SetDrawsContent(true);
root->AddChild(child2.Pass());
}
LayerImpl* child2 = root->children()[1];
EmulateDrawingOneFrame(root.get());
ClearDamageForAllSurfaces(root.get());
child1->SetUpdateRect(gfx::RectF(0.f, 0.f, 1.f, 2.f));
child2->SetUpdateRect(gfx::RectF(0.f, 0.f, 3.f, 4.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(
gfx::RectF(100.f, 100.f, 303.f, 284.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* child2 = root->children()[1];
LayerImpl* grand_child1 = root->children()[0]->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
grand_child1->SetOpacity(0.5f);
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(200.f, 200.f, 6.f, 8.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(300.f, 300.f, 6.f, 8.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
grand_child1->SetOpacity(0.7f);
child2->SetOpacity(0.7f);
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(200.f, 200.f, 6.f, 8.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(11.f, 11.f, 295.f, 297.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* grand_child1 = root->children()[0]->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(190.f, 190.f, 11.f, 23.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(290.f, 290.f, 16.f, 23.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
child1->SetPosition(gfx::PointF(50.f, 50.f));
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(190.f, 190.f, 16.f, 18.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(240.f, 240.f, 66.f, 68.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
child1->SetOpacity(1.f);
child1->SetForceRenderSurface(false);
EmulateDrawingOneFrame(root.get());
ASSERT_FALSE(child1->render_surface());
ASSERT_EQ(4u, root->render_surface()->layer_list().size());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(290.f, 290.f, 16.f, 18.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(root_damage_rect.IsEmpty());
ClearDamageForAllSurfaces(root.get());
child1->SetOpacity(0.5f);
child1->SetForceRenderSurface(true);
EmulateDrawingOneFrame(root.get());
ASSERT_TRUE(child1->render_surface());
EXPECT_EQ(3u, root->render_surface()->layer_list().size());
EXPECT_EQ(2u, child1->render_surface()->layer_list().size());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(190.f, 190.f, 16.f, 18.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(290.f, 290.f, 16.f, 18.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(child_damage_rect.IsEmpty());
EXPECT_TRUE(root_damage_rect.IsEmpty());
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(child_damage_rect.IsEmpty());
EXPECT_TRUE(root_damage_rect.IsEmpty());
}
TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
gfx::RectF child_damage_rect;
gfx::RectF root_damage_rect;
ClearDamageForAllSurfaces(root.get());
child1->SetUpdateRect(gfx::RectF(0.f, 0.f, 1.f, 2.f));
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(child_damage_rect.IsEmpty());
EXPECT_TRUE(root_damage_rect.IsEmpty());
}
TEST_F(DamageTrackerTest, VerifyDamageForReplica) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* grand_child1 = child1->children()[0];
LayerImpl* grand_child2 = child1->children()[1];
grand_child2->SetPosition(gfx::PointF(180.f, 180.f));
{
scoped_ptr<LayerImpl> grand_child3 =
LayerImpl::Create(host_impl_.active_tree(), 6);
grand_child3->SetPosition(gfx::PointF(240.f, 240.f));
grand_child3->SetAnchorPoint(gfx::PointF());
grand_child3->SetBounds(gfx::Size(10, 10));
grand_child3->SetContentBounds(gfx::Size(10, 10));
grand_child3->SetDrawsContent(true);
child1->AddChild(grand_child3.Pass());
}
child1->SetOpacity(0.5f);
EmulateDrawingOneFrame(root.get());
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> grand_child1_replica =
LayerImpl::Create(host_impl_.active_tree(), 7);
grand_child1_replica->SetPosition(gfx::PointF());
grand_child1_replica->SetAnchorPoint(gfx::PointF());
gfx::Transform reflection;
reflection.Scale3d(-1.0, 1.0, 1.0);
grand_child1_replica->SetTransform(reflection);
grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
}
EmulateDrawingOneFrame(root.get());
gfx::RectF grand_child_damage_rect =
grand_child1->render_surface()->damage_tracker()->
current_damage_rect();
gfx::RectF child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 8.f), grand_child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(194.f, 200.f, 12.f, 8.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(294.f, 300.f, 12.f, 8.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
gfx::Rect old_content_rect = child1->render_surface()->content_rect();
grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
EmulateDrawingOneFrame(root.get());
ASSERT_EQ(old_content_rect.width(),
child1->render_surface()->content_rect().width());
ASSERT_EQ(old_content_rect.height(),
child1->render_surface()->content_rect().height());
grand_child_damage_rect =
grand_child1->render_surface()->
damage_tracker()->current_damage_rect();
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 6.f, 8.f), grand_child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(189.f, 200.f, 17.f, 13.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(289.f, 300.f, 17.f, 13.f), root_damage_rect);
ClearDamageForAllSurfaces(root.get());
grand_child1->SetReplicaLayer(scoped_ptr<LayerImpl>());
EmulateDrawingOneFrame(root.get());
ASSERT_EQ(old_content_rect.width(),
child1->render_surface()->content_rect().width());
ASSERT_EQ(old_content_rect.height(),
child1->render_surface()->content_rect().height());
EXPECT_FALSE(grand_child1->render_surface());
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(189.f, 205.f, 12.f, 8.f), child_damage_rect);
EXPECT_FLOAT_RECT_EQ(gfx::RectF(289.f, 305.f, 12.f, 8.f), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForMask) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> mask_layer =
LayerImpl::Create(host_impl_.active_tree(), 3);
mask_layer->SetPosition(child->position());
mask_layer->SetAnchorPoint(gfx::PointF());
mask_layer->SetBounds(child->bounds());
mask_layer->SetContentBounds(child->bounds());
child->SetMaskLayer(mask_layer.Pass());
}
LayerImpl* mask_layer = child->mask_layer();
child->SetOpacity(0.5f);
{
scoped_ptr<LayerImpl> grand_child =
LayerImpl::Create(host_impl_.active_tree(), 4);
grand_child->SetPosition(gfx::PointF(2.f, 2.f));
grand_child->SetAnchorPoint(gfx::PointF());
grand_child->SetBounds(gfx::Size(2, 2));
grand_child->SetContentBounds(gfx::Size(2, 2));
grand_child->SetDrawsContent(true);
child->AddChild(grand_child.Pass());
}
EmulateDrawingOneFrame(root.get());
ASSERT_TRUE(child->render_surface());
ClearDamageForAllSurfaces(root.get());
mask_layer->SetUpdateRect(gfx::RectF(1.f, 2.f, 3.f, 4.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 30.f, 30.f), child_damage_rect);
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(child_damage_rect.IsEmpty());
ClearDamageForAllSurfaces(root.get());
mask_layer->SetStackingOrderChanged(true);
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 30.f, 30.f), child_damage_rect);
ClearDamageForAllSurfaces(root.get());
EmulateDrawingOneFrame(root.get());
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(child_damage_rect.IsEmpty());
ClearDamageForAllSurfaces(root.get());
child->SetMaskLayer(scoped_ptr<LayerImpl>());
ASSERT_TRUE(child->LayerPropertyChanged());
EmulateDrawingOneFrame(root.get());
ASSERT_TRUE(child->render_surface());
child_damage_rect =
child->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(0.f, 0.f, 30.f, 30.f), child_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* grand_child1 = child1->children()[0];
ClearDamageForAllSurfaces(root.get());
{
scoped_ptr<LayerImpl> grand_child1_replica =
LayerImpl::Create(host_impl_.active_tree(), 6);
grand_child1_replica->SetPosition(gfx::PointF());
grand_child1_replica->SetAnchorPoint(gfx::PointF());
gfx::Transform reflection;
reflection.Scale3d(-1.0, 1.0, 1.0);
grand_child1_replica->SetTransform(reflection);
grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
}
LayerImpl* grand_child1_replica = grand_child1->replica_layer();
{
scoped_ptr<LayerImpl> replica_mask_layer =
LayerImpl::Create(host_impl_.active_tree(), 7);
replica_mask_layer->SetPosition(gfx::PointF());
replica_mask_layer->SetAnchorPoint(gfx::PointF());
replica_mask_layer->SetBounds(grand_child1->bounds());
replica_mask_layer->SetContentBounds(grand_child1->bounds());
grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass());
}
LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
EmulateDrawingOneFrame(root.get());
ASSERT_TRUE(grand_child1->render_surface());
ClearDamageForAllSurfaces(root.get());
replica_mask_layer->SetStackingOrderChanged(true);
EmulateDrawingOneFrame(root.get());
gfx::RectF grand_child_damage_rect =
grand_child1->render_surface()->damage_tracker()->
current_damage_rect();
gfx::RectF child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
EXPECT_FLOAT_RECT_EQ(gfx::RectF(194.f, 200.f, 6.f, 8.f), child_damage_rect);
ClearDamageForAllSurfaces(root.get());
grand_child1_replica->SetMaskLayer(scoped_ptr<LayerImpl>());
EmulateDrawingOneFrame(root.get());
grand_child_damage_rect =
grand_child1->render_surface()->damage_tracker()->
current_damage_rect();
child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
EXPECT_FLOAT_RECT_EQ(gfx::RectF(194.f, 200.f, 6.f, 8.f), child_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithAnchor) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->children()[0];
LayerImpl* grand_child1 = child1->children()[0];
ClearDamageForAllSurfaces(root.get());
grand_child1->SetAnchorPoint(gfx::PointF(1.f, 0.f));
{
scoped_ptr<LayerImpl> grand_child1_replica =
LayerImpl::Create(host_impl_.active_tree(), 6);
grand_child1_replica->SetPosition(gfx::PointF());
grand_child1_replica->SetAnchorPoint(gfx::PointF(1.f, 0.f));
gfx::Transform reflection;
reflection.Scale3d(-1.0, 1.0, 1.0);
grand_child1_replica->SetTransform(reflection);
grand_child1->SetReplicaLayer(grand_child1_replica.Pass());
}
LayerImpl* grand_child1_replica = grand_child1->replica_layer();
{
scoped_ptr<LayerImpl> replica_mask_layer =
LayerImpl::Create(host_impl_.active_tree(), 7);
replica_mask_layer->SetPosition(gfx::PointF());
replica_mask_layer->SetAnchorPoint(gfx::PointF());
replica_mask_layer->SetBounds(grand_child1->bounds());
replica_mask_layer->SetContentBounds(grand_child1->bounds());
grand_child1_replica->SetMaskLayer(replica_mask_layer.Pass());
}
LayerImpl* replica_mask_layer = grand_child1_replica->mask_layer();
EmulateDrawingOneFrame(root.get());
ASSERT_TRUE(grand_child1->render_surface());
ClearDamageForAllSurfaces(root.get());
replica_mask_layer->SetStackingOrderChanged(true);
EmulateDrawingOneFrame(root.get());
gfx::RectF child_damage_rect =
child1->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(206.f, 200.f, 6.f, 8.f), child_damage_rect);
}
TEST_F(DamageTrackerTest, DamageWhenAddedExternally) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(10, 11, 12, 13));
root->render_surface()->damage_tracker()->AddDamageNextUpdate(
gfx::RectF(15, 16, 32, 33));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(
gfx::UnionRects(gfx::RectF(15, 16, 32, 33),
gfx::RectF(100+10, 100+11, 12, 13)),
root_damage_rect);
ClearDamageForAllSurfaces(root.get());
root->render_surface()->damage_tracker()->AddDamageNextUpdate(
gfx::RectF(30, 31, 14, 15));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(30, 31, 14, 15), root_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) {
scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl_.active_tree(), 1);
root->CreateRenderSurface();
ASSERT_TRUE(root == root->render_target());
RenderSurfaceImpl* target_surface = root->render_surface();
LayerImplList empty_list;
target_surface->damage_tracker()->UpdateDamageTrackingState(
empty_list,
target_surface->OwningLayerId(),
false,
gfx::Rect(),
NULL,
FilterOperations());
gfx::RectF damage_rect =
target_surface->damage_tracker()->current_damage_rect();
EXPECT_TRUE(damage_rect.IsEmpty());
}
TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) {
scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->children()[0];
ClearDamageForAllSurfaces(root.get());
child->SetUpdateRect(gfx::RectF(10.f, 11.f, 1.f, 2.f));
EmulateDrawingOneFrame(root.get());
gfx::RectF root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(110.f, 111.f, 1.f, 2.f), root_damage_rect);
child->SetUpdateRect(gfx::RectF(20.f, 25.f, 1.f, 2.f));
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_FLOAT_RECT_EQ(gfx::RectF(110.f, 111.f, 11.f, 16.f), root_damage_rect);
root->render_surface()->damage_tracker()->DidDrawDamagedArea();
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(root_damage_rect.IsEmpty());
EmulateDrawingOneFrame(root.get());
root_damage_rect =
root->render_surface()->damage_tracker()->current_damage_rect();
EXPECT_TRUE(root_damage_rect.IsEmpty());
}
}
}