summaryrefslogtreecommitdiffstats
path: root/cc/layers/delegated_renderer_layer_unittest.cc
blob: ce7dab013e54f6e2e83b92696cad1e1ca94a6721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 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/layers/delegated_renderer_layer.h"

#include "cc/layers/delegated_frame_provider.h"
#include "cc/layers/delegated_frame_resource_collection.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/test/fake_delegated_renderer_layer.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

class DelegatedRendererLayerTest : public testing::Test {
 public:
  DelegatedRendererLayerTest() : proxy_() {
    LayerTreeSettings settings;
    settings.minimum_occlusion_tracking_size = gfx::Size();

    host_impl_ = FakeLayerTreeHost::Create(settings);
    host_impl_->SetViewportSize(gfx::Size(10, 10));
  }

 protected:
  FakeProxy proxy_;
  TestSharedBitmapManager shared_bitmap_manager_;
  scoped_ptr<LayerTreeHost> host_impl_;
};

class DelegatedRendererLayerTestSimple : public DelegatedRendererLayerTest {
 public:
  DelegatedRendererLayerTestSimple() : DelegatedRendererLayerTest() {
    scoped_ptr<RenderPass> root_pass(RenderPass::Create());
    root_pass->SetNew(
        RenderPassId(1, 1), gfx::Rect(1, 1), gfx::Rect(1, 1), gfx::Transform());
    scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
    frame_data->render_pass_list.push_back(root_pass.Pass());
    resources_ = new DelegatedFrameResourceCollection;
    provider_ = new DelegatedFrameProvider(resources_, frame_data.Pass());
    root_layer_ = SolidColorLayer::Create();
    layer_before_ = SolidColorLayer::Create();
    delegated_renderer_layer_ =
        FakeDelegatedRendererLayer::Create(provider_.get());
  }

 protected:
  scoped_refptr<Layer> root_layer_;
  scoped_refptr<Layer> layer_before_;
  scoped_refptr<DelegatedRendererLayer> delegated_renderer_layer_;
  scoped_refptr<DelegatedFrameResourceCollection> resources_;
  scoped_refptr<DelegatedFrameProvider> provider_;
};

TEST_F(DelegatedRendererLayerTestSimple, DelegatedManyDescendants) {
  EXPECT_EQ(0, root_layer_->NumDescendantsThatDrawContent());
  root_layer_->AddChild(layer_before_);
  EXPECT_EQ(0, root_layer_->NumDescendantsThatDrawContent());
  layer_before_->SetIsDrawable(true);
  EXPECT_EQ(1, root_layer_->NumDescendantsThatDrawContent());
  EXPECT_EQ(0, layer_before_->NumDescendantsThatDrawContent());
  layer_before_->AddChild(delegated_renderer_layer_);
  EXPECT_EQ(0, layer_before_->NumDescendantsThatDrawContent());
  EXPECT_EQ(0, delegated_renderer_layer_->NumDescendantsThatDrawContent());
  EXPECT_EQ(1, root_layer_->NumDescendantsThatDrawContent());
  delegated_renderer_layer_->SetIsDrawable(true);
  EXPECT_EQ(1000, delegated_renderer_layer_->NumDescendantsThatDrawContent());
  EXPECT_EQ(1001, layer_before_->NumDescendantsThatDrawContent());
  EXPECT_EQ(1002, root_layer_->NumDescendantsThatDrawContent());
}

}  // namespace
}  // namespace cc