blob: 9a5f839e8c06560fc49ed3b47dfaaac9e04aea6b [file] [log] [blame]
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/trees/occlusion_tracker.h"
#include "cc/animation/layer_animation_controller.h"
#include "cc/base/math_util.h"
#include "cc/debug/overdraw_metrics.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_impl.h"
#include "cc/output/filter_operation.h"
#include "cc/output/filter_operations.h"
#include "cc/test/animation_test_common.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/occlusion_tracker_test_common.h"
#include "cc/trees/layer_tree_host_common.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/transform.h"
namespace cc {
namespace {
class TestContentLayer : public Layer {
public:
TestContentLayer() : Layer(), override_opaque_contents_rect_(false) {}
virtual bool DrawsContent() const OVERRIDE { return true; }
virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
if (override_opaque_contents_rect_)
return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
return Layer::VisibleContentOpaqueRegion();
}
void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) {
override_opaque_contents_rect_ = true;
opaque_contents_rect_ = opaque_contents_rect;
}
private:
virtual ~TestContentLayer() {}
bool override_opaque_contents_rect_;
gfx::Rect opaque_contents_rect_;
};
class TestContentLayerImpl : public LayerImpl {
public:
TestContentLayerImpl(LayerTreeImpl* tree_impl, int id)
: LayerImpl(tree_impl, id), override_opaque_contents_rect_(false) {
SetDrawsContent(true);
}
virtual Region VisibleContentOpaqueRegion() const OVERRIDE {
if (override_opaque_contents_rect_)
return gfx::IntersectRects(opaque_contents_rect_, visible_content_rect());
return LayerImpl::VisibleContentOpaqueRegion();
}
void SetOpaqueContentsRect(gfx::Rect opaque_contents_rect) {
override_opaque_contents_rect_ = true;
opaque_contents_rect_ = opaque_contents_rect;
}
private:
bool override_opaque_contents_rect_;
gfx::Rect opaque_contents_rect_;
};
static inline bool LayerImplDrawTransformIsUnknown(const Layer* layer) {
return layer->draw_transform_is_animating();
}
static inline bool LayerImplDrawTransformIsUnknown(const LayerImpl* layer) {
return false;
}
template <typename LayerType, typename RenderSurfaceType>
class TestOcclusionTrackerWithClip
: public TestOcclusionTrackerBase<LayerType, RenderSurfaceType> {
public:
TestOcclusionTrackerWithClip(gfx::Rect viewport_rect,
bool record_metrics_for_frame)
: TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(
viewport_rect,
record_metrics_for_frame) {}
explicit TestOcclusionTrackerWithClip(gfx::Rect viewport_rect)
: TestOcclusionTrackerBase<LayerType, RenderSurfaceType>(viewport_rect,
false) {}
bool OccludedLayer(const LayerType* layer, gfx::Rect content_rect) {
bool temp;
return OccludedLayer(layer, content_rect, &temp);
}
bool OccludedLayer(const LayerType* layer,
gfx::Rect content_rect,
bool* has_occlusion_from_outside_target_surface) const {
return this->Occluded(layer->render_target(),
content_rect,
layer->draw_transform(),
LayerImplDrawTransformIsUnknown(layer),
layer->is_clipped(),
layer->clip_rect(),
has_occlusion_from_outside_target_surface);
}
// Gives an unoccluded sub-rect of |content_rect| in the content space of the
// layer. Simple wrapper around UnoccludedContentRect.
gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
gfx::Rect content_rect) const {
bool temp;
return UnoccludedLayerContentRect(layer, content_rect, &temp);
}
gfx::Rect UnoccludedLayerContentRect(
const LayerType* layer,
gfx::Rect content_rect,
bool* has_occlusion_from_outside_target_surface) const {
return this->UnoccludedContentRect(
layer->render_target(),
content_rect,
layer->draw_transform(),
LayerImplDrawTransformIsUnknown(layer),
layer->is_clipped(),
layer->clip_rect(),
has_occlusion_from_outside_target_surface);
}
};
struct OcclusionTrackerTestMainThreadTypes {
typedef Layer LayerType;
typedef LayerTreeHost HostType;
typedef RenderSurface RenderSurfaceType;
typedef TestContentLayer ContentLayerType;
typedef scoped_refptr<Layer> LayerPtrType;
typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
typedef LayerIterator<Layer,
LayerList,
RenderSurface,
LayerIteratorActions::FrontToBack> TestLayerIterator;
typedef OcclusionTracker OcclusionTrackerType;
static LayerPtrType CreateLayer(HostType* host) { return Layer::Create(); }
static ContentLayerPtrType CreateContentLayer(HostType* host) {
return make_scoped_refptr(new ContentLayerType());
}
static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
LayerPtrType ref(*layer);
*layer = NULL;
return ref;
}
static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
LayerPtrType ref(*layer);
*layer = NULL;
return ref;
}
static void DestroyLayer(LayerPtrType* layer) { *layer = NULL; }
};
struct OcclusionTrackerTestImplThreadTypes {
typedef LayerImpl LayerType;
typedef LayerTreeImpl HostType;
typedef RenderSurfaceImpl RenderSurfaceType;
typedef TestContentLayerImpl ContentLayerType;
typedef scoped_ptr<LayerImpl> LayerPtrType;
typedef scoped_ptr<ContentLayerType> ContentLayerPtrType;
typedef LayerIterator<LayerImpl,
LayerImplList,
RenderSurfaceImpl,
LayerIteratorActions::FrontToBack> TestLayerIterator;
typedef OcclusionTrackerImpl OcclusionTrackerType;
static LayerPtrType CreateLayer(HostType* host) {
return LayerImpl::Create(host, next_layer_impl_id++);
}
static ContentLayerPtrType CreateContentLayer(HostType* host) {
return make_scoped_ptr(new ContentLayerType(host, next_layer_impl_id++));
}
static int next_layer_impl_id;
static LayerPtrType PassLayerPtr(LayerPtrType* layer) {
return layer->Pass();
}
static LayerPtrType PassLayerPtr(ContentLayerPtrType* layer) {
return layer->PassAs<LayerType>();
}
static void DestroyLayer(LayerPtrType* layer) { layer->reset(); }
};
int OcclusionTrackerTestImplThreadTypes::next_layer_impl_id = 1;
template <typename Types> class OcclusionTrackerTest : public testing::Test {
protected:
explicit OcclusionTrackerTest(bool opaque_layers)
: host_impl_(&proxy_), opaque_layers_(opaque_layers) {}
virtual void RunMyTest() = 0;
virtual void TearDown() {
Types::DestroyLayer(&root_);
render_surface_layer_list_.clear();
render_surface_layer_list_impl_.clear();
replica_layers_.clear();
mask_layers_.clear();
}
typename Types::HostType* GetHost();
typename Types::ContentLayerType* CreateRoot(const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
typename Types::ContentLayerPtrType layer(
Types::CreateContentLayer(GetHost()));
typename Types::ContentLayerType* layer_ptr = layer.get();
SetProperties(layer_ptr, transform, position, bounds);
DCHECK(!root_.get());
root_ = Types::PassLayerPtr(&layer);
return layer_ptr;
}
typename Types::LayerType* CreateLayer(typename Types::LayerType* parent,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
typename Types::LayerPtrType layer(Types::CreateLayer(GetHost()));
typename Types::LayerType* layer_ptr = layer.get();
SetProperties(layer_ptr, transform, position, bounds);
parent->AddChild(Types::PassLayerPtr(&layer));
return layer_ptr;
}
typename Types::LayerType* CreateSurface(typename Types::LayerType* parent,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
typename Types::LayerType* layer =
CreateLayer(parent, transform, position, bounds);
layer->SetForceRenderSurface(true);
return layer;
}
typename Types::ContentLayerType* CreateDrawingLayer(
typename Types::LayerType* parent,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds,
bool opaque) {
typename Types::ContentLayerPtrType layer(
Types::CreateContentLayer(GetHost()));
typename Types::ContentLayerType* layer_ptr = layer.get();
SetProperties(layer_ptr, transform, position, bounds);
if (opaque_layers_) {
layer_ptr->SetContentsOpaque(opaque);
} else {
layer_ptr->SetContentsOpaque(false);
if (opaque)
layer_ptr->SetOpaqueContentsRect(gfx::Rect(bounds));
else
layer_ptr->SetOpaqueContentsRect(gfx::Rect());
}
parent->AddChild(Types::PassLayerPtr(&layer));
return layer_ptr;
}
typename Types::LayerType* CreateReplicaLayer(
typename Types::LayerType* owning_layer,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
typename Types::ContentLayerPtrType layer(
Types::CreateContentLayer(GetHost()));
typename Types::ContentLayerType* layer_ptr = layer.get();
SetProperties(layer_ptr, transform, position, bounds);
SetReplica(owning_layer, Types::PassLayerPtr(&layer));
return layer_ptr;
}
typename Types::LayerType* CreateMaskLayer(
typename Types::LayerType* owning_layer,
gfx::Size bounds) {
typename Types::ContentLayerPtrType layer(
Types::CreateContentLayer(GetHost()));
typename Types::ContentLayerType* layer_ptr = layer.get();
SetProperties(layer_ptr, identity_matrix, gfx::PointF(), bounds);
SetMask(owning_layer, Types::PassLayerPtr(&layer));
return layer_ptr;
}
typename Types::ContentLayerType* CreateDrawingSurface(
typename Types::LayerType* parent,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds,
bool opaque) {
typename Types::ContentLayerType* layer =
CreateDrawingLayer(parent, transform, position, bounds, opaque);
layer->SetForceRenderSurface(true);
return layer;
}
void CalcDrawEtc(TestContentLayerImpl* root) {
DCHECK(root == root_.get());
int dummy_max_texture_size = 512;
DCHECK(!root->render_surface());
LayerTreeHostCommon::CalculateDrawProperties(
root,
root->bounds(),
gfx::Transform(),
1.f,
1.f,
NULL,
dummy_max_texture_size,
false, // can_use_lcd_text
true, // can_adjust_raster_scales
&render_surface_layer_list_impl_);
layer_iterator_ = layer_iterator_begin_ =
Types::TestLayerIterator::Begin(&render_surface_layer_list_impl_);
}
void CalcDrawEtc(TestContentLayer* root) {
DCHECK(root == root_.get());
int dummy_max_texture_size = 512;
DCHECK(!root->render_surface());
LayerTreeHostCommon::CalculateDrawProperties(
root,
root->bounds(),
gfx::Transform(),
1.f,
1.f,
NULL,
dummy_max_texture_size,
false, // can_use_lcd_text
true, // can_adjust_raster_scales
&render_surface_layer_list_);
layer_iterator_ = layer_iterator_begin_ =
Types::TestLayerIterator::Begin(&render_surface_layer_list_);
}
void EnterLayer(typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion,
bool prevent_occlusion) {
ASSERT_EQ(layer, *layer_iterator_);
ASSERT_TRUE(layer_iterator_.represents_itself());
occlusion->EnterLayer(layer_iterator_, prevent_occlusion);
}
void LeaveLayer(typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion) {
ASSERT_EQ(layer, *layer_iterator_);
ASSERT_TRUE(layer_iterator_.represents_itself());
occlusion->LeaveLayer(layer_iterator_);
++layer_iterator_;
}
void VisitLayer(typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion) {
EnterLayer(layer, occlusion, false);
LeaveLayer(layer, occlusion);
}
void EnterContributingSurface(
typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion,
bool prevent_occlusion) {
ASSERT_EQ(layer, *layer_iterator_);
ASSERT_TRUE(layer_iterator_.represents_target_render_surface());
occlusion->EnterLayer(layer_iterator_, false);
occlusion->LeaveLayer(layer_iterator_);
++layer_iterator_;
ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
occlusion->EnterLayer(layer_iterator_, prevent_occlusion);
}
void LeaveContributingSurface(
typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion) {
ASSERT_EQ(layer, *layer_iterator_);
ASSERT_TRUE(layer_iterator_.represents_contributing_render_surface());
occlusion->LeaveLayer(layer_iterator_);
++layer_iterator_;
}
void VisitContributingSurface(
typename Types::LayerType* layer,
typename Types::OcclusionTrackerType* occlusion) {
EnterContributingSurface(layer, occlusion, false);
LeaveContributingSurface(layer, occlusion);
}
void ResetLayerIterator() { layer_iterator_ = layer_iterator_begin_; }
const gfx::Transform identity_matrix;
private:
void SetBaseProperties(typename Types::LayerType* layer,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
layer->SetTransform(transform);
layer->SetSublayerTransform(gfx::Transform());
layer->SetAnchorPoint(gfx::PointF());
layer->SetPosition(position);
layer->SetBounds(bounds);
}
void SetProperties(Layer* layer,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
SetBaseProperties(layer, transform, position, bounds);
}
void SetProperties(LayerImpl* layer,
const gfx::Transform& transform,
gfx::PointF position,
gfx::Size bounds) {
SetBaseProperties(layer, transform, position, bounds);
layer->SetContentBounds(layer->bounds());
}
void SetReplica(Layer* owning_layer, scoped_refptr<Layer> layer) {
owning_layer->SetReplicaLayer(layer.get());
replica_layers_.push_back(layer);
}
void SetReplica(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
owning_layer->SetReplicaLayer(layer.Pass());
}
void SetMask(Layer* owning_layer, scoped_refptr<Layer> layer) {
owning_layer->SetMaskLayer(layer.get());
mask_layers_.push_back(layer);
}
void SetMask(LayerImpl* owning_layer, scoped_ptr<LayerImpl> layer) {
owning_layer->SetMaskLayer(layer.Pass());
}
FakeImplProxy proxy_;
FakeLayerTreeHostImpl host_impl_;
bool opaque_layers_;
// These hold ownership of the layers for the duration of the test.
typename Types::LayerPtrType root_;
LayerList render_surface_layer_list_;
LayerImplList render_surface_layer_list_impl_;
typename Types::TestLayerIterator layer_iterator_begin_;
typename Types::TestLayerIterator layer_iterator_;
typename Types::LayerType* last_layer_visited_;
LayerList replica_layers_;
LayerList mask_layers_;
};
template <>
LayerTreeHost*
OcclusionTrackerTest<OcclusionTrackerTestMainThreadTypes>::GetHost() {
return NULL;
}
template <>
LayerTreeImpl*
OcclusionTrackerTest<OcclusionTrackerTestImplThreadTypes>::GetHost() {
return host_impl_.active_tree();
}
#define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
class ClassName##MainThreadOpaqueLayers \
: public ClassName<OcclusionTrackerTestMainThreadTypes> { \
public: /* NOLINT(whitespace/indent) */ \
ClassName##MainThreadOpaqueLayers() \
: ClassName<OcclusionTrackerTestMainThreadTypes>(true) {} \
}; \
TEST_F(ClassName##MainThreadOpaqueLayers, RunTest) { RunMyTest(); }
#define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
class ClassName##MainThreadOpaquePaints \
: public ClassName<OcclusionTrackerTestMainThreadTypes> { \
public: /* NOLINT(whitespace/indent) */ \
ClassName##MainThreadOpaquePaints() \
: ClassName<OcclusionTrackerTestMainThreadTypes>(false) {} \
}; \
TEST_F(ClassName##MainThreadOpaquePaints, RunTest) { RunMyTest(); }
#define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
class ClassName##ImplThreadOpaqueLayers \
: public ClassName<OcclusionTrackerTestImplThreadTypes> { \
public: /* NOLINT(whitespace/indent) */ \
ClassName##ImplThreadOpaqueLayers() \
: ClassName<OcclusionTrackerTestImplThreadTypes>(true) {} \
}; \
TEST_F(ClassName##ImplThreadOpaqueLayers, RunTest) { RunMyTest(); }
#define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
class ClassName##ImplThreadOpaquePaints \
: public ClassName<OcclusionTrackerTestImplThreadTypes> { \
public: /* NOLINT(whitespace/indent) */ \
ClassName##ImplThreadOpaquePaints() \
: ClassName<OcclusionTrackerTestImplThreadTypes>(false) {} \
}; \
TEST_F(ClassName##ImplThreadOpaquePaints, RunTest) { RunMyTest(); }
#define ALL_OCCLUSIONTRACKER_TEST(ClassName) \
RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
#define MAIN_THREAD_TEST(ClassName) \
RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName)
#define IMPL_THREAD_TEST(ClassName) \
RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
#define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
template <class Types>
class OcclusionTrackerTestIdentityTransforms
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestIdentityTransforms(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
parent->SetMasksToBounds(true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000), false);
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 30, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 30, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 31, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 31, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 31, 70, 70)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
template <class Types>
class OcclusionTrackerTestQuadsMismatchLayer
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform layer_transform;
layer_transform.Translate(10.0, 10.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100));
typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true);
typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer2, &occlusion);
this->EnterLayer(layer1, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// This checks cases where the quads don't match their "containing"
// layers, e.g. in terms of transforms or clip rect. This is typical for
// DelegatedRendererLayer.
gfx::Transform quad_transform;
quad_transform.Translate(30.0, 30.0);
gfx::Rect clip_rect_in_target(0, 0, 100, 100);
EXPECT_TRUE(occlusion.UnoccludedContentRect(parent,
gfx::Rect(0, 0, 10, 10),
quad_transform,
false,
true,
clip_rect_in_target,
NULL).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(0, 0, 10, 10),
occlusion.UnoccludedContentRect(parent,
gfx::Rect(0, 0, 10, 10),
quad_transform,
true,
true,
clip_rect_in_target,
NULL));
EXPECT_RECT_EQ(gfx::Rect(40, 40, 10, 10),
occlusion.UnoccludedContentRect(parent,
gfx::Rect(40, 40, 10, 10),
quad_transform,
false,
true,
clip_rect_in_target,
NULL));
EXPECT_RECT_EQ(gfx::Rect(40, 30, 5, 10),
occlusion.UnoccludedContentRect(parent,
gfx::Rect(35, 30, 10, 10),
quad_transform,
false,
true,
clip_rect_in_target,
NULL));
EXPECT_RECT_EQ(gfx::Rect(40, 40, 5, 5),
occlusion.UnoccludedContentRect(parent,
gfx::Rect(40, 40, 10, 10),
quad_transform,
false,
true,
gfx::Rect(0, 0, 75, 75),
NULL));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
template <class Types>
class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform layer_transform;
layer_transform.Translate(250.0, 250.0);
layer_transform.Rotate(90.0);
layer_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::Point(0, 0), gfx::Size(200, 200));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(parent,
layer_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
parent->SetMasksToBounds(true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 70, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 70, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 70, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 70, 70)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 70),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 30, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(29, 29, 70, 70),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(31, 29, 69, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 29, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 30, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 31, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 31, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(29, 31, 1, 69),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 31, 70, 70)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
template <class Types>
class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform layer_transform;
layer_transform.Translate(20.0, 20.0);
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(parent,
layer_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
parent->SetMasksToBounds(true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 50, 50, 50)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(49, 50, 50, 50)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(50, 49, 50, 50)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(51, 50, 50, 50)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(50, 51, 50, 50)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(49, 50, 1, 50),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(49, 50, 50, 50)));
EXPECT_RECT_EQ(gfx::Rect(49, 49, 50, 50),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(49, 49, 50, 50)));
EXPECT_RECT_EQ(gfx::Rect(50, 49, 50, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(50, 49, 50, 50)));
EXPECT_RECT_EQ(gfx::Rect(51, 49, 49, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(51, 49, 50, 50)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(51, 50, 50, 50)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(51, 51, 50, 50)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(50, 51, 50, 50)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(49, 51, 1, 49),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(49, 51, 50, 50)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
template <class Types>
class OcclusionTrackerTestChildInRotatedChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child_transform;
child_transform.Translate(250.0, 250.0);
child_transform.Rotate(90.0);
child_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
parent->SetMasksToBounds(true);
typename Types::LayerType* child = this->CreateSurface(
parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
child->SetMasksToBounds(true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(child,
this->identity_matrix,
gfx::PointF(10.f, 10.f),
gfx::Size(500, 500),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer, &occlusion);
this->EnterContributingSurface(child, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->LeaveContributingSurface(child, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(31, 40, 70, 60)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 41, 70, 60)));
/* Justification for the above occlusion from |layer|:
100
+---------------------+
| |
| 30 | rotate(90)
| 30 + ---------------------------------+
100 | | 10 | | ==>
| |10+---------------------------------+
| | | | | |
| | | | | |
| | | | | |
+----|--|-------------+ | |
| | | |
| | | |
| | | |500
| | | |
| | | |
| | | |
| | | |
+--|-------------------------------+ |
| |
+---------------------------------+
500
+---------------------+
| |30 Visible region of |layer|: /////
| |
| +---------------------------------+
100| | |10 |
| +---------------------------------+ |
| | |///////////////| 420 | |
| | |///////////////|60 | |
| | |///////////////| | |
+--|--|---------------+ | |
20|10| 70 | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |10|
| +------------------------------|--+
| 490 |
+---------------------------------+
500
*/
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestChildInRotatedChild);
template <class Types>
class OcclusionTrackerTestScaledRenderSurface
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestScaledRenderSurface(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
gfx::Transform layer1_matrix;
layer1_matrix.Scale(2.0, 2.0);
typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
parent, layer1_matrix, gfx::PointF(), gfx::Size(100, 100), true);
layer1->SetForceRenderSurface(true);
gfx::Transform layer2_matrix;
layer2_matrix.Translate(25.0, 25.0);
typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
layer1, layer2_matrix, gfx::PointF(), gfx::Size(50, 50), true);
typename Types::ContentLayerType* occluder =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(100.f, 100.f),
gfx::Size(500, 500),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(occluder, &occlusion);
this->EnterLayer(layer2, &occlusion, false);
EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_RECT_EQ(
gfx::Rect(0, 0, 25, 25),
occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
EXPECT_RECT_EQ(gfx::Rect(10, 25, 15, 25),
occlusion.UnoccludedLayerContentRect(
layer2, gfx::Rect(10, 25, 25, 25)));
EXPECT_RECT_EQ(gfx::Rect(25, 10, 25, 15),
occlusion.UnoccludedLayerContentRect(
layer2, gfx::Rect(25, 10, 25, 25)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
template <class Types>
class OcclusionTrackerTestVisitTargetTwoTimes
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child_transform;
child_transform.Translate(250.0, 250.0);
child_transform.Rotate(90.0);
child_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(200, 200));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
parent->SetMasksToBounds(true);
typename Types::LayerType* child = this->CreateSurface(
parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
child->SetMasksToBounds(true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(child,
this->identity_matrix,
gfx::PointF(10.f, 10.f),
gfx::Size(500, 500),
true);
// |child2| makes |parent|'s surface get considered by OcclusionTracker
// first, instead of |child|'s. This exercises different code in
// LeaveToRenderTarget, as the target surface has already been seen.
typename Types::ContentLayerType* child2 =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(30.f, 30.f),
gfx::Size(60, 20),
true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(child2, &occlusion);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(30, 30, 60, 20).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->VisitLayer(layer, &occlusion);
EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->EnterContributingSurface(child, &occlusion, false);
EXPECT_EQ(gfx::Rect(0, 440, 20, 60).ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// Occlusion in |child2| should get merged with the |child| surface we are
// leaving now.
this->LeaveContributingSurface(child, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(UnionRegions(gfx::Rect(30, 30, 60, 10), gfx::Rect(30, 40, 70, 60))
.ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 70, 70)));
EXPECT_RECT_EQ(gfx::Rect(90, 30, 10, 10),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 30, 70, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 30, 60, 10)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 30, 60, 10)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 29, 60, 10)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(31, 30, 60, 10)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 31, 60, 10)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 30, 60, 10)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(29, 30, 1, 10),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 30, 60, 10)));
EXPECT_RECT_EQ(gfx::Rect(30, 29, 60, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 29, 60, 10)));
EXPECT_RECT_EQ(gfx::Rect(90, 30, 1, 10),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 30, 60, 10)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 31, 60, 10)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 40, 70, 60)));
// This rect is mostly occluded by |child2|.
EXPECT_RECT_EQ(gfx::Rect(90, 39, 10, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 39, 70, 60)));
// This rect extends past top/right ends of |child2|.
EXPECT_RECT_EQ(gfx::Rect(30, 29, 70, 11),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 29, 70, 70)));
// This rect extends past left/right ends of |child2|.
EXPECT_RECT_EQ(gfx::Rect(20, 39, 80, 60),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(20, 39, 80, 60)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 40, 70, 60)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 41, 70, 60)));
/* Justification for the above occlusion from |layer|:
100
+---------------------+
| |
| 30 | rotate(90)
| 30 + ------------+--------------------+
100 | | 10 | | | ==>
| |10+----------|----------------------+
| + ------------+ | | |
| | | | | |
| | | | | |
+----|--|-------------+ | |
| | | |
| | | |
| | | |500
| | | |
| | | |
| | | |
| | | |
+--|-------------------------------+ |
| |
+---------------------------------+
500
+---------------------+
| |30 Visible region of |layer|: /////
| 30 60 | |child2|: \\\\\
| 30 +------------+--------------------+
| |\\\\\\\\\\\\| |10 |
| +--|\\\\\\\\\\\\|-----------------+ |
| | +------------+//| 420 | |
| | |///////////////|60 | |
| | |///////////////| | |
+--|--|---------------+ | |
20|10| 70 | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |10|
| +------------------------------|--+
| 490 |
+---------------------------------+
500
*/
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestVisitTargetTwoTimes);
template <class Types>
class OcclusionTrackerTestSurfaceRotatedOffAxis
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestSurfaceRotatedOffAxis(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child_transform;
child_transform.Translate(250.0, 250.0);
child_transform.Rotate(95.0);
child_transform.Translate(-250.0, -250.0);
gfx::Transform layer_transform;
layer_transform.Translate(10.0, 10.0);
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
typename Types::LayerType* child = this->CreateLayer(
parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(500, 500));
child->SetMasksToBounds(true);
typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
child, layer_transform, gfx::PointF(), gfx::Size(500, 500), true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
gfx::Rect clipped_layer_in_child = MathUtil::MapClippedRect(
layer_transform, layer->visible_content_rect());
this->VisitLayer(layer, &occlusion);
this->EnterContributingSurface(child, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(clipped_layer_in_child.ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->LeaveContributingSurface(child, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(75, 55, 1, 1)));
EXPECT_RECT_EQ(
gfx::Rect(75, 55, 1, 1),
occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
template <class Types>
class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child_transform;
child_transform.Translate(250.0, 250.0);
child_transform.Rotate(90.0);
child_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* root = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(1000, 1000));
typename Types::ContentLayerType* parent = this->CreateDrawingLayer(
root, this->identity_matrix, gfx::PointF(), gfx::Size(100, 100), true);
parent->SetMasksToBounds(true);
typename Types::ContentLayerType* child =
this->CreateDrawingSurface(parent,
child_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
false);
child->SetMasksToBounds(true);
typename Types::ContentLayerType* layer1 =
this->CreateDrawingLayer(child,
this->identity_matrix,
gfx::PointF(10.f, 10.f),
gfx::Size(500, 500),
true);
typename Types::ContentLayerType* layer2 =
this->CreateDrawingLayer(child,
this->identity_matrix,
gfx::PointF(10.f, 450.f),
gfx::Size(500, 60),
true);
this->CalcDrawEtc(root);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer2, &occlusion);
this->VisitLayer(layer1, &occlusion);
this->VisitLayer(child, &occlusion);
this->EnterContributingSurface(child, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 430, 60, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(child, gfx::Rect(9, 430, 60, 70)));
// These rects are occluded except for the part outside the bounds of the
// target surface.
EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 429, 60, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(11, 430, 60, 70)));
EXPECT_TRUE(occlusion.OccludedLayer(child, gfx::Rect(10, 431, 60, 70)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
EXPECT_RECT_EQ(
gfx::Rect(9, 430, 1, 70),
occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
// These rects are occluded except for the part outside the bounds of the
// target surface.
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
child, gfx::Rect(10, 429, 60, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
child, gfx::Rect(11, 430, 60, 70)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
child, gfx::Rect(10, 431, 60, 70)));
this->LeaveContributingSurface(child, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 40, 70, 60)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 39, 70, 60)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
EXPECT_RECT_EQ(gfx::Rect(29, 40, 1, 60),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(29, 40, 70, 60)));
EXPECT_RECT_EQ(gfx::Rect(30, 39, 70, 1),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 39, 70, 60)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(31, 40, 70, 60)));
EXPECT_RECT_EQ(gfx::Rect(),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(30, 41, 70, 60)));
/* Justification for the above occlusion from |layer1| and |layer2|:
+---------------------+
| |30 Visible region of |layer1|: /////
| | Visible region of |layer2|: \\\\\
| +---------------------------------+
| | |10 |
| +---------------+-----------------+ |
| | |\\\\\\\\\\\\|//| 420 | |
| | |\\\\\\\\\\\\|//|60 | |
| | |\\\\\\\\\\\\|//| | |
+--|--|------------|--+ | |
20|10| 70 | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | |10|
| +------------|-----------------|--+
| | 490 |
+---------------+-----------------+
60 440
*/
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
template <class Types>
class OcclusionTrackerTestOverlappingSurfaceSiblings
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestOverlappingSurfaceSiblings(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child_transform;
child_transform.Translate(250.0, 250.0);
child_transform.Rotate(90.0);
child_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
parent->SetMasksToBounds(true);
typename Types::LayerType* child1 = this->CreateSurface(
parent, child_transform, gfx::PointF(30.f, 30.f), gfx::Size(10, 10));
typename Types::LayerType* child2 = this->CreateSurface(
parent, child_transform, gfx::PointF(20.f, 40.f), gfx::Size(10, 10));
typename Types::ContentLayerType* layer1 =
this->CreateDrawingLayer(child1,
this->identity_matrix,
gfx::PointF(-10.f, -10.f),
gfx::Size(510, 510),
true);
typename Types::ContentLayerType* layer2 =
this->CreateDrawingLayer(child2,
this->identity_matrix,
gfx::PointF(-10.f, -10.f),
gfx::Size(510, 510),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer2, &occlusion);
this->EnterContributingSurface(child2, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 70, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-11, 420, 70, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 419, 70, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 71, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(child2, gfx::Rect(-10, 420, 70, 81)));
// There is nothing above child2's surface in the z-order.
EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
occlusion.UnoccludedContributingSurfaceContentRect(
child2, false, gfx::Rect(-10, 420, 70, 80), NULL));
this->LeaveContributingSurface(child2, &occlusion);
this->VisitLayer(layer1, &occlusion);
this->EnterContributingSurface(child1, &occlusion, false);
EXPECT_EQ(gfx::Rect(0, 430, 70, 80).ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(-10, 430, 80, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// child2's contents will occlude child1 below it.
EXPECT_RECT_EQ(gfx::Rect(-10, 430, 10, 70),
occlusion.UnoccludedContributingSurfaceContentRect(
child1, false, gfx::Rect(-10, 430, 80, 70), NULL));
this->LeaveContributingSurface(child1, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(UnionRegions(gfx::Rect(30, 20, 70, 10), gfx::Rect(20, 30, 80, 70))
.ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 20, 80, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(30, 20, 70, 80)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(29, 20, 70, 80)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(30, 19, 70, 80)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(20, 30, 80, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(19, 30, 80, 70)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(20, 29, 80, 70)));
/* Justification for the above occlusion:
100
+---------------------+
| 20 | layer1
| 30+ ---------------------------------+
100 | 30| | layer2 |
|20+----------------------------------+ |
| | | | | |
| | | | | |
| | | | | |
+--|-|----------------+ | |
| | | | 510
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| +--------------------------------|-+
| |
+----------------------------------+
510
*/
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOverlappingSurfaceSiblings);
template <class Types>
class OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms(
bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform child1_transform;
child1_transform.Translate(250.0, 250.0);
child1_transform.Rotate(-90.0);
child1_transform.Translate(-250.0, -250.0);
gfx::Transform child2_transform;
child2_transform.Translate(250.0, 250.0);
child2_transform.Rotate(90.0);
child2_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
parent->SetMasksToBounds(true);
typename Types::LayerType* child1 = this->CreateSurface(
parent, child1_transform, gfx::PointF(30.f, 20.f), gfx::Size(10, 10));
typename Types::LayerType* child2 =
this->CreateDrawingSurface(parent,
child2_transform,
gfx::PointF(20.f, 40.f),
gfx::Size(10, 10),
false);
typename Types::ContentLayerType* layer1 =
this->CreateDrawingLayer(child1,
this->identity_matrix,
gfx::PointF(-10.f, -20.f),
gfx::Size(510, 510),
true);
typename Types::ContentLayerType* layer2 =
this->CreateDrawingLayer(child2,
this->identity_matrix,
gfx::PointF(-10.f, -10.f),
gfx::Size(510, 510),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(layer2, &occlusion);
this->EnterLayer(child2, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->LeaveLayer(child2, &occlusion);
this->EnterContributingSurface(child2, &occlusion, false);
// There is nothing above child2's surface in the z-order.
EXPECT_RECT_EQ(gfx::Rect(-10, 420, 70, 80),
occlusion.UnoccludedContributingSurfaceContentRect(
child2, false, gfx::Rect(-10, 420, 70, 80), NULL));
this->LeaveContributingSurface(child2, &occlusion);
this->VisitLayer(layer1, &occlusion);
this->EnterContributingSurface(child1, &occlusion, false);
EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// child2's contents will occlude child1 below it.
EXPECT_RECT_EQ(gfx::Rect(420, -20, 80, 90),
occlusion.UnoccludedContributingSurfaceContentRect(
child1, false, gfx::Rect(420, -20, 80, 90), NULL));
EXPECT_RECT_EQ(gfx::Rect(490, -10, 10, 80),
occlusion.UnoccludedContributingSurfaceContentRect(
child1, false, gfx::Rect(420, -10, 80, 90), NULL));
EXPECT_RECT_EQ(gfx::Rect(420, -20, 70, 10),
occlusion.UnoccludedContributingSurfaceContentRect(
child1, false, gfx::Rect(420, -20, 70, 90), NULL));
this->LeaveContributingSurface(child1, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect().ToString(),
occlusion.occlusion_from_outside_target().ToString());
EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
occlusion.occlusion_from_inside_target().ToString());
/* Justification for the above occlusion:
100
+---------------------+
|20 | layer1
10+----------------------------------+
100 || 30 | layer2 |
|20+----------------------------------+
|| | | | |
|| | | | |
|| | | | |
+|-|------------------+ | |
| | | | 510
| | 510 | |
| | | |
| | | |
| | | |
| | | |
| | 520 | |
+----------------------------------+ |
| |
+----------------------------------+
510
*/
}
};
ALL_OCCLUSIONTRACKER_TEST(
OcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
template <class Types>
class OcclusionTrackerTestFilters : public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestFilters(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform layer_transform;
layer_transform.Translate(250.0, 250.0);
layer_transform.Rotate(90.0);
layer_transform.Translate(-250.0, -250.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 100));
parent->SetMasksToBounds(true);
typename Types::ContentLayerType* blur_layer =
this->CreateDrawingLayer(parent,
layer_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
typename Types::ContentLayerType* opaque_layer =
this->CreateDrawingLayer(parent,
layer_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
typename Types::ContentLayerType* opacity_layer =
this->CreateDrawingLayer(parent,
layer_transform,
gfx::PointF(30.f, 30.f),
gfx::Size(500, 500),
true);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(10.f));
blur_layer->SetFilters(filters);
filters.Clear();
filters.Append(FilterOperation::CreateGrayscaleFilter(0.5f));
opaque_layer->SetFilters(filters);
filters.Clear();
filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
opacity_layer->SetFilters(filters);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
// Opacity layer won't contribute to occlusion.
this->VisitLayer(opacity_layer, &occlusion);
this->EnterContributingSurface(opacity_layer, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
// And has nothing to contribute to its parent surface.
this->LeaveContributingSurface(opacity_layer, &occlusion);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
// Opaque layer will contribute to occlusion.
this->VisitLayer(opaque_layer, &occlusion);
this->EnterContributingSurface(opaque_layer, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_EQ(gfx::Rect(0, 430, 70, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// And it gets translated to the parent surface.
this->LeaveContributingSurface(opaque_layer, &occlusion);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
// The blur layer needs to throw away any occlusion from outside its
// subtree.
this->EnterLayer(blur_layer, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
// And it won't contribute to occlusion.
this->LeaveLayer(blur_layer, &occlusion);
this->EnterContributingSurface(blur_layer, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
// But the opaque layer's occlusion is preserved on the parent.
this->LeaveContributingSurface(blur_layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
occlusion.occlusion_from_inside_target().ToString());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestFilters);
template <class Types>
class OcclusionTrackerTestReplicaDoesOcclude
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestReplicaDoesOcclude(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
typename Types::LayerType* surface =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(0.f, 100.f),
gfx::Size(50, 50),
true);
this->CreateReplicaLayer(
surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(surface, &occlusion);
EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->VisitContributingSurface(surface, &occlusion);
this->EnterLayer(parent, &occlusion, false);
// The surface and replica should both be occluding the parent.
EXPECT_EQ(
UnionRegions(gfx::Rect(0, 100, 50, 50),
gfx::Rect(50, 150, 50, 50)).ToString(),
occlusion.occlusion_from_inside_target().ToString());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaDoesOcclude);
template <class Types>
class OcclusionTrackerTestReplicaWithClipping
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestReplicaWithClipping(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 170));
parent->SetMasksToBounds(true);
typename Types::LayerType* surface =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(0.f, 100.f),
gfx::Size(50, 50),
true);
this->CreateReplicaLayer(
surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(surface, &occlusion);
EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->VisitContributingSurface(surface, &occlusion);
this->EnterLayer(parent, &occlusion, false);
// The surface and replica should both be occluding the parent.
EXPECT_EQ(
UnionRegions(gfx::Rect(0, 100, 50, 50),
gfx::Rect(50, 150, 50, 20)).ToString(),
occlusion.occlusion_from_inside_target().ToString());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithClipping);
template <class Types>
class OcclusionTrackerTestReplicaWithMask : public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestReplicaWithMask(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
typename Types::LayerType* surface =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(0.f, 100.f),
gfx::Size(50, 50),
true);
typename Types::LayerType* replica = this->CreateReplicaLayer(
surface, this->identity_matrix, gfx::PointF(50.f, 50.f), gfx::Size());
this->CreateMaskLayer(replica, gfx::Size(10, 10));
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(surface, &occlusion);
EXPECT_EQ(gfx::Rect(0, 0, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->VisitContributingSurface(surface, &occlusion);
this->EnterLayer(parent, &occlusion, false);
// The replica should not be occluding the parent, since it has a mask
// applied to it.
EXPECT_EQ(gfx::Rect(0, 100, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaWithMask);
template <class Types>
class OcclusionTrackerTestLayerClipRectOutsideChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestLayerClipRectOutsideChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* clip =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(200.f, 100.f),
gfx::Size(100, 100),
false);
clip->SetMasksToBounds(true);
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(clip,
this->identity_matrix,
gfx::PointF(-200.f, -100.f),
gfx::Size(200, 200),
false);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->EnterLayer(clip, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(-100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, -100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100)));
EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
occlusion.UnoccludedLayerContentRect(
clip, gfx::Rect(-100, -100, 300, 300)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOutsideChild);
template <class Types>
class OcclusionTrackerTestViewportRectOutsideChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestViewportRectOutsideChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(200, 100, 100, 100));
this->EnterLayer(layer, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
EXPECT_RECT_EQ(gfx::Rect(200, 100, 100, 100),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 300)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOutsideChild);
template <class Types>
class OcclusionTrackerTestLayerClipRectOverChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestLayerClipRectOverChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* clip =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(100.f, 100.f),
gfx::Size(100, 100),
false);
clip->SetMasksToBounds(true);
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(clip,
this->identity_matrix,
gfx::PointF(-100.f, -100.f),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
occlusion.occlusion_from_inside_target().ToString());
this->EnterLayer(clip, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(0, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(100, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(clip, gfx::Rect(200, 200, 100, 100)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
clip, gfx::Rect(0, 0, 300, 300)).IsEmpty());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectOverChild);
template <class Types>
class OcclusionTrackerTestViewportRectOverChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestViewportRectOverChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(100, 100, 100, 100));
this->EnterLayer(layer, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverChild);
template <class Types>
class OcclusionTrackerTestLayerClipRectPartlyOverChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestLayerClipRectPartlyOverChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* clip =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(50.f, 50.f),
gfx::Size(200, 200),
false);
clip->SetMasksToBounds(true);
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(clip,
this->identity_matrix,
gfx::PointF(-50.f, -50.f),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 50)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 50, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 50)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 50, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(clip, &occlusion, false);
EXPECT_EQ(gfx::Rect(50, 50, 150, 150).ToString(),
occlusion.occlusion_from_inside_target().ToString());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectPartlyOverChild);
template <class Types>
class OcclusionTrackerTestViewportRectPartlyOverChild
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestViewportRectPartlyOverChild(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(50, 50, 200, 200));
this->EnterLayer(layer, &occlusion, false);
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
EXPECT_RECT_EQ(gfx::Rect(50, 50, 200, 200),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 300)));
EXPECT_RECT_EQ(gfx::Rect(200, 50, 50, 50),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 100)));
EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 100, 300, 100)));
EXPECT_RECT_EQ(gfx::Rect(200, 100, 50, 100),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(200, 100, 100, 100)));
EXPECT_RECT_EQ(gfx::Rect(100, 200, 100, 50),
occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(100, 200, 100, 100)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectPartlyOverChild);
template <class Types>
class OcclusionTrackerTestViewportRectOverNothing
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestViewportRectOverNothing(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(500, 500, 100, 100));
this->EnterLayer(layer, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 100, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 0, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(0, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(100, 200, 100, 100)));
EXPECT_TRUE(occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 300)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 0, 300, 100)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(0, 100, 300, 100)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(200, 100, 100, 100)).IsEmpty());
EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
parent, gfx::Rect(100, 200, 100, 100)).IsEmpty());
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestViewportRectOverNothing);
template <class Types>
class OcclusionTrackerTestLayerClipRectForLayerOffOrigin
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestLayerClipRectForLayerOffOrigin(
bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
// This layer is translated when drawn into its target. So if the clip rect
// given from the target surface is not in that target space, then after
// translating these query rects into the target, they will fall outside the
// clip and be considered occluded.
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
}
};
ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestLayerClipRectForLayerOffOrigin);
template <class Types>
class OcclusionTrackerTestOpaqueContentsRegionEmpty
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestOpaqueContentsRegionEmpty(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingSurface(parent,
this->identity_matrix,
gfx::PointF(),
gfx::Size(200, 200),
false);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 0, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(occlusion.OccludedLayer(layer, gfx::Rect(100, 100, 100, 100)));
// Occluded since its outside the surface bounds.
EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(200, 100, 100, 100)));
this->LeaveLayer(layer, &occlusion);
this->VisitContributingSurface(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
}
};
MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionEmpty);
template <class Types>
class OcclusionTrackerTestOpaqueContentsRegionNonEmpty
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestOpaqueContentsRegionNonEmpty(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(parent,
this->identity_matrix,
gfx::PointF(100.f, 100.f),
gfx::Size(200, 200),
false);
this->CalcDrawEtc(parent);
{
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
layer->SetOpaqueContentsRect(gfx::Rect(0, 0, 100, 100));
this->ResetLayerIterator();
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_TRUE(
occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
}
{
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
layer->SetOpaqueContentsRect(gfx::Rect(20, 20, 180, 180));
this->ResetLayerIterator();
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect(120, 120, 180, 180).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_TRUE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
}
{
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
layer->SetOpaqueContentsRect(gfx::Rect(150, 150, 100, 100));
this->ResetLayerIterator();
this->VisitLayer(layer, &occlusion);
this->EnterLayer(parent, &occlusion, false);
EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
occlusion.occlusion_from_inside_target().ToString());
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(0, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(100, 100, 100, 100)));
EXPECT_FALSE(
occlusion.OccludedLayer(parent, gfx::Rect(200, 200, 100, 100)));
}
}
};
MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
template <class Types>
class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTest3dTransform(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform transform;
transform.RotateAboutYAxis(30.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::LayerType* container = this->CreateLayer(
parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(container,
transform,
gfx::PointF(100.f, 100.f),
gfx::Size(200, 200),
true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->EnterLayer(layer, &occlusion, false);
// The layer is rotated in 3d but without preserving 3d, so it only gets
// resized.
EXPECT_RECT_EQ(
gfx::Rect(0, 0, 200, 200),
occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
}
};
MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
template <class Types>
class OcclusionTrackerTestUnsorted3dLayers
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
// Currently, The main thread layer iterator does not iterate over 3d items
// in sorted order, because layer sorting is not performed on the main
// thread. Because of this, the occlusion tracker cannot assume that a 3d
// layer occludes other layers that have not yet been iterated over. For
// now, the expected behavior is that a 3d layer simply does not add any
// occlusion to the occlusion tracker.
gfx::Transform translation_to_front;
translation_to_front.Translate3d(0.0, 0.0, -10.0);
gfx::Transform translation_to_back;
translation_to_front.Translate3d(0.0, 0.0, -100.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* child1 = this->CreateDrawingLayer(
parent, translation_to_back, gfx::PointF(), gfx::Size(100, 100), true);
typename Types::ContentLayerType* child2 =
this->CreateDrawingLayer(parent,
translation_to_front,
gfx::PointF(50.f, 50.f),
gfx::Size(100, 100),
true);
parent->SetPreserves3d(true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(0, 0, 1000, 1000));
this->VisitLayer(child2, &occlusion);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
this->VisitLayer(child1, &occlusion);
EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
}
};
// This test will have different layer ordering on the impl thread; the test
// will only work on the main thread.
MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
template <class Types>
class OcclusionTrackerTestPerspectiveTransform
: public OcclusionTrackerTest<Types> {
protected:
explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers)
: OcclusionTrackerTest<Types>(opaque_layers) {}
void RunMyTest() {
gfx::Transform transform;
transform.Translate(150.0, 150.0);
transform.ApplyPerspectiveDepth(400.0);
transform.RotateAboutXAxis(-30.0);
transform.Translate(-150.0, -150.0);
typename Types::ContentLayerType* parent = this->CreateRoot(
this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::LayerType* container = this->CreateLayer(
parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
typename Types::ContentLayerType* layer =
this->CreateDrawingLayer(container,
transform,
gfx::PointF(100.f, 100.f),
gfx::Size(200, 200),
true);
container->SetPreserves3d(true);
layer->SetPreserves3d(true);
this->CalcDrawEtc(parent);
TestOcclusionTrackerWithClip<typename Types::LayerType,
typename Types::RenderSurfaceType> occlusion(
gfx::Rect(