summaryrefslogtreecommitdiffstats
path: root/cc/layers/layer_iterator_unittest.cc
diff options
context:
space:
mode:
authoralexst@chromium.org <alexst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 21:30:09 +0000
committeralexst@chromium.org <alexst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 21:30:09 +0000
commit71dfcc7a69bffa9ad2fbc853406bd6117e93895f (patch)
tree3e0db4eef413d33cac5b00619054275c0656f44b /cc/layers/layer_iterator_unittest.cc
parentb1c602bfa89f06d411fbd13961451c913b31d9f4 (diff)
downloadchromium_src-71dfcc7a69bffa9ad2fbc853406bd6117e93895f.zip
chromium_src-71dfcc7a69bffa9ad2fbc853406bd6117e93895f.tar.gz
chromium_src-71dfcc7a69bffa9ad2fbc853406bd6117e93895f.tar.bz2
Chromify layer_iterator.
BUG= Review URL: https://chromiumcodereview.appspot.com/12737008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layers/layer_iterator_unittest.cc')
-rw-r--r--cc/layers/layer_iterator_unittest.cc449
1 files changed, 238 insertions, 211 deletions
diff --git a/cc/layers/layer_iterator_unittest.cc b/cc/layers/layer_iterator_unittest.cc
index 9d4dc52..464c570 100644
--- a/cc/layers/layer_iterator_unittest.cc
+++ b/cc/layers/layer_iterator_unittest.cc
@@ -19,235 +19,262 @@ namespace cc {
namespace {
class TestLayer : public Layer {
-public:
- static scoped_refptr<TestLayer> Create() { return make_scoped_refptr(new TestLayer()); }
-
- int m_countRepresentingTargetSurface;
- int m_countRepresentingContributingSurface;
- int m_countRepresentingItself;
-
- virtual bool DrawsContent() const OVERRIDE { return m_drawsContent; }
- void setDrawsContent(bool drawsContent) { m_drawsContent = drawsContent; }
-
-private:
- TestLayer()
- : Layer()
- , m_drawsContent(true)
- {
- SetBounds(gfx::Size(100, 100));
- SetPosition(gfx::Point());
- SetAnchorPoint(gfx::Point());
- }
- virtual ~TestLayer()
- {
- }
-
- bool m_drawsContent;
+ public:
+ static scoped_refptr<TestLayer> Create() {
+ return make_scoped_refptr(new TestLayer());
+ }
+
+ int count_representing_target_surface_;
+ int count_representing_contributing_surface_;
+ int count_representing_itself_;
+
+ virtual bool DrawsContent() const OVERRIDE { return draws_content_; }
+ void set_draws_content(bool draws_content) { draws_content_ = draws_content; }
+
+ private:
+ TestLayer() : Layer(), draws_content_(true) {
+ SetBounds(gfx::Size(100, 100));
+ SetPosition(gfx::Point());
+ SetAnchorPoint(gfx::Point());
+ }
+ virtual ~TestLayer() {}
+
+ bool draws_content_;
};
-#define EXPECT_COUNT(layer, target, contrib, itself) \
- EXPECT_EQ(target, layer->m_countRepresentingTargetSurface); \
- EXPECT_EQ(contrib, layer->m_countRepresentingContributingSurface); \
- EXPECT_EQ(itself, layer->m_countRepresentingItself);
-
-typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::FrontToBack> FrontToBack;
-typedef LayerIterator<Layer, std::vector<scoped_refptr<Layer> >, RenderSurface, LayerIteratorActions::BackToFront> BackToFront;
-
-void resetCounts(std::vector<scoped_refptr<Layer> >& renderSurfaceLayerList)
-{
- for (unsigned surfaceIndex = 0; surfaceIndex < renderSurfaceLayerList.size(); ++surfaceIndex) {
- TestLayer* renderSurfaceLayer = static_cast<TestLayer*>(renderSurfaceLayerList[surfaceIndex].get());
- RenderSurface* renderSurface = renderSurfaceLayer->render_surface();
-
- renderSurfaceLayer->m_countRepresentingTargetSurface = -1;
- renderSurfaceLayer->m_countRepresentingContributingSurface = -1;
- renderSurfaceLayer->m_countRepresentingItself = -1;
-
- for (unsigned layerIndex = 0; layerIndex < renderSurface->layer_list().size(); ++layerIndex) {
- TestLayer* layer = static_cast<TestLayer*>(renderSurface->layer_list()[layerIndex].get());
-
- layer->m_countRepresentingTargetSurface = -1;
- layer->m_countRepresentingContributingSurface = -1;
- layer->m_countRepresentingItself = -1;
- }
+#define EXPECT_COUNT(layer, target, contrib, itself) \
+ EXPECT_EQ(target, layer->count_representing_target_surface_); \
+ EXPECT_EQ(contrib, layer->count_representing_contributing_surface_); \
+ EXPECT_EQ(itself, layer->count_representing_itself_);
+
+typedef LayerIterator<Layer,
+ std::vector<scoped_refptr<Layer> >,
+ RenderSurface,
+ LayerIteratorActions::FrontToBack> FrontToBack;
+typedef LayerIterator<Layer,
+ std::vector<scoped_refptr<Layer> >,
+ RenderSurface,
+ LayerIteratorActions::BackToFront> BackToFront;
+
+void ResetCounts(std::vector<scoped_refptr<Layer> >* render_surface_layerList) {
+ for (unsigned surface_index = 0;
+ surface_index < render_surface_layerList->size();
+ ++surface_index) {
+ TestLayer* render_surface_layer = static_cast<TestLayer*>(
+ (*render_surface_layerList)[surface_index].get());
+ RenderSurface* render_surface = render_surface_layer->render_surface();
+
+ render_surface_layer->count_representing_target_surface_ = -1;
+ render_surface_layer->count_representing_contributing_surface_ = -1;
+ render_surface_layer->count_representing_itself_ = -1;
+
+ for (unsigned layer_index = 0;
+ layer_index < render_surface->layer_list().size();
+ ++layer_index) {
+ TestLayer* layer = static_cast<TestLayer*>(
+ render_surface->layer_list()[layer_index].get());
+
+ layer->count_representing_target_surface_ = -1;
+ layer->count_representing_contributing_surface_ = -1;
+ layer->count_representing_itself_ = -1;
}
+ }
}
-void iterateFrontToBack(std::vector<scoped_refptr<Layer> >* renderSurfaceLayerList)
-{
- resetCounts(*renderSurfaceLayerList);
- int count = 0;
- for (FrontToBack it = FrontToBack::begin(renderSurfaceLayerList); it != FrontToBack::end(renderSurfaceLayerList); ++it, ++count) {
- TestLayer* layer = static_cast<TestLayer*>(*it);
- if (it.representsTargetRenderSurface())
- layer->m_countRepresentingTargetSurface = count;
- if (it.representsContributingRenderSurface())
- layer->m_countRepresentingContributingSurface = count;
- if (it.representsItself())
- layer->m_countRepresentingItself = count;
- }
+void IterateFrontToBack(
+ std::vector<scoped_refptr<Layer> >* render_surface_layerList) {
+ ResetCounts(render_surface_layerList);
+ int count = 0;
+ for (FrontToBack it = FrontToBack::Begin(render_surface_layerList);
+ it != FrontToBack::End(render_surface_layerList);
+ ++it, ++count) {
+ TestLayer* layer = static_cast<TestLayer*>(*it);
+ if (it.represents_target_render_surface())
+ layer->count_representing_target_surface_ = count;
+ if (it.represents_contributing_render_surface())
+ layer->count_representing_contributing_surface_ = count;
+ if (it.represents_itself())
+ layer->count_representing_itself_ = count;
+ }
}
-void iterateBackToFront(std::vector<scoped_refptr<Layer> >* renderSurfaceLayerList)
-{
- resetCounts(*renderSurfaceLayerList);
- int count = 0;
- for (BackToFront it = BackToFront::begin(renderSurfaceLayerList); it != BackToFront::end(renderSurfaceLayerList); ++it, ++count) {
- TestLayer* layer = static_cast<TestLayer*>(*it);
- if (it.representsTargetRenderSurface())
- layer->m_countRepresentingTargetSurface = count;
- if (it.representsContributingRenderSurface())
- layer->m_countRepresentingContributingSurface = count;
- if (it.representsItself())
- layer->m_countRepresentingItself = count;
- }
+void IterateBackToFront(
+ std::vector<scoped_refptr<Layer> >* render_surface_layerList) {
+ ResetCounts(render_surface_layerList);
+ int count = 0;
+ for (BackToFront it = BackToFront::Begin(render_surface_layerList);
+ it != BackToFront::End(render_surface_layerList);
+ ++it, ++count) {
+ TestLayer* layer = static_cast<TestLayer*>(*it);
+ if (it.represents_target_render_surface())
+ layer->count_representing_target_surface_ = count;
+ if (it.represents_contributing_render_surface())
+ layer->count_representing_contributing_surface_ = count;
+ if (it.represents_itself())
+ layer->count_representing_itself_ = count;
+ }
}
-TEST(LayerIteratorTest, emptyTree)
-{
- std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
+TEST(LayerIteratorTest, EmptyTree) {
+ std::vector<scoped_refptr<Layer> > render_surface_layerList;
- iterateBackToFront(&renderSurfaceLayerList);
- iterateFrontToBack(&renderSurfaceLayerList);
+ IterateBackToFront(&render_surface_layerList);
+ IterateFrontToBack(&render_surface_layerList);
}
-TEST(LayerIteratorTest, simpleTree)
-{
- scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
- scoped_refptr<TestLayer> first = TestLayer::Create();
- scoped_refptr<TestLayer> second = TestLayer::Create();
- scoped_refptr<TestLayer> third = TestLayer::Create();
- scoped_refptr<TestLayer> fourth = TestLayer::Create();
-
- rootLayer->CreateRenderSurface();
-
- rootLayer->AddChild(first);
- rootLayer->AddChild(second);
- rootLayer->AddChild(third);
- rootLayer->AddChild(fourth);
-
- std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
- LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList);
-
- iterateBackToFront(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 0, -1, 1);
- EXPECT_COUNT(first, -1, -1, 2);
- EXPECT_COUNT(second, -1, -1, 3);
- EXPECT_COUNT(third, -1, -1, 4);
- EXPECT_COUNT(fourth, -1, -1, 5);
-
- iterateFrontToBack(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 5, -1, 4);
- EXPECT_COUNT(first, -1, -1, 3);
- EXPECT_COUNT(second, -1, -1, 2);
- EXPECT_COUNT(third, -1, -1, 1);
- EXPECT_COUNT(fourth, -1, -1, 0);
+TEST(LayerIteratorTest, SimpleTree) {
+ scoped_refptr<TestLayer> root_layer = TestLayer::Create();
+ scoped_refptr<TestLayer> first = TestLayer::Create();
+ scoped_refptr<TestLayer> second = TestLayer::Create();
+ scoped_refptr<TestLayer> third = TestLayer::Create();
+ scoped_refptr<TestLayer> fourth = TestLayer::Create();
+
+ root_layer->CreateRenderSurface();
+
+ root_layer->AddChild(first);
+ root_layer->AddChild(second);
+ root_layer->AddChild(third);
+ root_layer->AddChild(fourth);
+
+ std::vector<scoped_refptr<Layer> > render_surface_layerList;
+ LayerTreeHostCommon::calculateDrawProperties(root_layer.get(),
+ root_layer->bounds(),
+ 1,
+ 1,
+ 256,
+ false,
+ render_surface_layerList);
+
+ IterateBackToFront(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 0, -1, 1);
+ EXPECT_COUNT(first, -1, -1, 2);
+ EXPECT_COUNT(second, -1, -1, 3);
+ EXPECT_COUNT(third, -1, -1, 4);
+ EXPECT_COUNT(fourth, -1, -1, 5);
+
+ IterateFrontToBack(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 5, -1, 4);
+ EXPECT_COUNT(first, -1, -1, 3);
+ EXPECT_COUNT(second, -1, -1, 2);
+ EXPECT_COUNT(third, -1, -1, 1);
+ EXPECT_COUNT(fourth, -1, -1, 0);
}
-TEST(LayerIteratorTest, complexTree)
-{
- scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
- scoped_refptr<TestLayer> root1 = TestLayer::Create();
- scoped_refptr<TestLayer> root2 = TestLayer::Create();
- scoped_refptr<TestLayer> root3 = TestLayer::Create();
- scoped_refptr<TestLayer> root21 = TestLayer::Create();
- scoped_refptr<TestLayer> root22 = TestLayer::Create();
- scoped_refptr<TestLayer> root23 = TestLayer::Create();
- scoped_refptr<TestLayer> root221 = TestLayer::Create();
- scoped_refptr<TestLayer> root231 = TestLayer::Create();
-
- rootLayer->CreateRenderSurface();
-
- rootLayer->AddChild(root1);
- rootLayer->AddChild(root2);
- rootLayer->AddChild(root3);
- root2->AddChild(root21);
- root2->AddChild(root22);
- root2->AddChild(root23);
- root22->AddChild(root221);
- root23->AddChild(root231);
-
- std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
- LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList);
-
- iterateBackToFront(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 0, -1, 1);
- EXPECT_COUNT(root1, -1, -1, 2);
- EXPECT_COUNT(root2, -1, -1, 3);
- EXPECT_COUNT(root21, -1, -1, 4);
- EXPECT_COUNT(root22, -1, -1, 5);
- EXPECT_COUNT(root221, -1, -1, 6);
- EXPECT_COUNT(root23, -1, -1, 7);
- EXPECT_COUNT(root231, -1, -1, 8);
- EXPECT_COUNT(root3, -1, -1, 9);
-
- iterateFrontToBack(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 9, -1, 8);
- EXPECT_COUNT(root1, -1, -1, 7);
- EXPECT_COUNT(root2, -1, -1, 6);
- EXPECT_COUNT(root21, -1, -1, 5);
- EXPECT_COUNT(root22, -1, -1, 4);
- EXPECT_COUNT(root221, -1, -1, 3);
- EXPECT_COUNT(root23, -1, -1, 2);
- EXPECT_COUNT(root231, -1, -1, 1);
- EXPECT_COUNT(root3, -1, -1, 0);
+TEST(LayerIteratorTest, ComplexTree) {
+ scoped_refptr<TestLayer> root_layer = TestLayer::Create();
+ scoped_refptr<TestLayer> root1 = TestLayer::Create();
+ scoped_refptr<TestLayer> root2 = TestLayer::Create();
+ scoped_refptr<TestLayer> root3 = TestLayer::Create();
+ scoped_refptr<TestLayer> root21 = TestLayer::Create();
+ scoped_refptr<TestLayer> root22 = TestLayer::Create();
+ scoped_refptr<TestLayer> root23 = TestLayer::Create();
+ scoped_refptr<TestLayer> root221 = TestLayer::Create();
+ scoped_refptr<TestLayer> root231 = TestLayer::Create();
+
+ root_layer->CreateRenderSurface();
+
+ root_layer->AddChild(root1);
+ root_layer->AddChild(root2);
+ root_layer->AddChild(root3);
+ root2->AddChild(root21);
+ root2->AddChild(root22);
+ root2->AddChild(root23);
+ root22->AddChild(root221);
+ root23->AddChild(root231);
+
+ std::vector<scoped_refptr<Layer> > render_surface_layerList;
+ LayerTreeHostCommon::calculateDrawProperties(root_layer.get(),
+ root_layer->bounds(),
+ 1,
+ 1,
+ 256,
+ false,
+ render_surface_layerList);
+
+ IterateBackToFront(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 0, -1, 1);
+ EXPECT_COUNT(root1, -1, -1, 2);
+ EXPECT_COUNT(root2, -1, -1, 3);
+ EXPECT_COUNT(root21, -1, -1, 4);
+ EXPECT_COUNT(root22, -1, -1, 5);
+ EXPECT_COUNT(root221, -1, -1, 6);
+ EXPECT_COUNT(root23, -1, -1, 7);
+ EXPECT_COUNT(root231, -1, -1, 8);
+ EXPECT_COUNT(root3, -1, -1, 9);
+
+ IterateFrontToBack(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 9, -1, 8);
+ EXPECT_COUNT(root1, -1, -1, 7);
+ EXPECT_COUNT(root2, -1, -1, 6);
+ EXPECT_COUNT(root21, -1, -1, 5);
+ EXPECT_COUNT(root22, -1, -1, 4);
+ EXPECT_COUNT(root221, -1, -1, 3);
+ EXPECT_COUNT(root23, -1, -1, 2);
+ EXPECT_COUNT(root231, -1, -1, 1);
+ EXPECT_COUNT(root3, -1, -1, 0);
}
-TEST(LayerIteratorTest, complexTreeMultiSurface)
-{
- scoped_refptr<TestLayer> rootLayer = TestLayer::Create();
- scoped_refptr<TestLayer> root1 = TestLayer::Create();
- scoped_refptr<TestLayer> root2 = TestLayer::Create();
- scoped_refptr<TestLayer> root3 = TestLayer::Create();
- scoped_refptr<TestLayer> root21 = TestLayer::Create();
- scoped_refptr<TestLayer> root22 = TestLayer::Create();
- scoped_refptr<TestLayer> root23 = TestLayer::Create();
- scoped_refptr<TestLayer> root221 = TestLayer::Create();
- scoped_refptr<TestLayer> root231 = TestLayer::Create();
-
- rootLayer->CreateRenderSurface();
- rootLayer->render_surface()->SetContentRect(gfx::Rect(gfx::Point(), rootLayer->bounds()));
-
- rootLayer->AddChild(root1);
- rootLayer->AddChild(root2);
- rootLayer->AddChild(root3);
- root2->setDrawsContent(false);
- root2->SetOpacity(0.5);
- root2->SetForceRenderSurface(true); // Force the layer to own a new surface.
- root2->AddChild(root21);
- root2->AddChild(root22);
- root2->AddChild(root23);
- root22->SetOpacity(0.5);
- root22->AddChild(root221);
- root23->SetOpacity(0.5);
- root23->AddChild(root231);
-
- std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
- LayerTreeHostCommon::calculateDrawProperties(rootLayer.get(), rootLayer->bounds(), 1, 1, 256, false, renderSurfaceLayerList);
-
- iterateBackToFront(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 0, -1, 1);
- EXPECT_COUNT(root1, -1, -1, 2);
- EXPECT_COUNT(root2, 4, 3, -1);
- EXPECT_COUNT(root21, -1, -1, 5);
- EXPECT_COUNT(root22, 7, 6, 8);
- EXPECT_COUNT(root221, -1, -1, 9);
- EXPECT_COUNT(root23, 11, 10, 12);
- EXPECT_COUNT(root231, -1, -1, 13);
- EXPECT_COUNT(root3, -1, -1, 14);
-
- iterateFrontToBack(&renderSurfaceLayerList);
- EXPECT_COUNT(rootLayer, 14, -1, 13);
- EXPECT_COUNT(root1, -1, -1, 12);
- EXPECT_COUNT(root2, 10, 11, -1);
- EXPECT_COUNT(root21, -1, -1, 9);
- EXPECT_COUNT(root22, 7, 8, 6);
- EXPECT_COUNT(root221, -1, -1, 5);
- EXPECT_COUNT(root23, 3, 4, 2);
- EXPECT_COUNT(root231, -1, -1, 1);
- EXPECT_COUNT(root3, -1, -1, 0);
+TEST(LayerIteratorTest, ComplexTreeMultiSurface) {
+ scoped_refptr<TestLayer> root_layer = TestLayer::Create();
+ scoped_refptr<TestLayer> root1 = TestLayer::Create();
+ scoped_refptr<TestLayer> root2 = TestLayer::Create();
+ scoped_refptr<TestLayer> root3 = TestLayer::Create();
+ scoped_refptr<TestLayer> root21 = TestLayer::Create();
+ scoped_refptr<TestLayer> root22 = TestLayer::Create();
+ scoped_refptr<TestLayer> root23 = TestLayer::Create();
+ scoped_refptr<TestLayer> root221 = TestLayer::Create();
+ scoped_refptr<TestLayer> root231 = TestLayer::Create();
+
+ root_layer->CreateRenderSurface();
+ root_layer->render_surface()->
+ SetContentRect(gfx::Rect(gfx::Point(), root_layer->bounds()));
+
+ root_layer->AddChild(root1);
+ root_layer->AddChild(root2);
+ root_layer->AddChild(root3);
+ root2->set_draws_content(false);
+ root2->SetOpacity(0.5f);
+ root2->SetForceRenderSurface(true); // Force the layer to own a new surface.
+ root2->AddChild(root21);
+ root2->AddChild(root22);
+ root2->AddChild(root23);
+ root22->SetOpacity(0.5f);
+ root22->AddChild(root221);
+ root23->SetOpacity(0.5f);
+ root23->AddChild(root231);
+
+ std::vector<scoped_refptr<Layer> > render_surface_layerList;
+ LayerTreeHostCommon::calculateDrawProperties(root_layer.get(),
+ root_layer->bounds(),
+ 1,
+ 1,
+ 256,
+ false,
+ render_surface_layerList);
+
+ IterateBackToFront(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 0, -1, 1);
+ EXPECT_COUNT(root1, -1, -1, 2);
+ EXPECT_COUNT(root2, 4, 3, -1);
+ EXPECT_COUNT(root21, -1, -1, 5);
+ EXPECT_COUNT(root22, 7, 6, 8);
+ EXPECT_COUNT(root221, -1, -1, 9);
+ EXPECT_COUNT(root23, 11, 10, 12);
+ EXPECT_COUNT(root231, -1, -1, 13);
+ EXPECT_COUNT(root3, -1, -1, 14);
+
+ IterateFrontToBack(&render_surface_layerList);
+ EXPECT_COUNT(root_layer, 14, -1, 13);
+ EXPECT_COUNT(root1, -1, -1, 12);
+ EXPECT_COUNT(root2, 10, 11, -1);
+ EXPECT_COUNT(root21, -1, -1, 9);
+ EXPECT_COUNT(root22, 7, 8, 6);
+ EXPECT_COUNT(root221, -1, -1, 5);
+ EXPECT_COUNT(root23, 3, 4, 2);
+ EXPECT_COUNT(root231, -1, -1, 1);
+ EXPECT_COUNT(root3, -1, -1, 0);
}
} // namespace