Update V8 to version 4.7.21.
[chromium-blink-merge.git] / cc / test / layer_test_common.h
bloba915b597d0c33f5309684cc3f4f30a67e5702a00
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_TEST_LAYER_TEST_COMMON_H_
6 #define CC_TEST_LAYER_TEST_COMMON_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/quads/render_pass.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/test_task_graph_runner.h"
13 #include "cc/trees/layer_tree_host_impl.h"
15 #define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) \
16 do { \
17 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
18 code_to_test; \
19 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
20 } while (false)
22 #define EXPECT_SET_NEEDS_UPDATE(expect, code_to_test) \
23 do { \
24 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times((expect)); \
25 code_to_test; \
26 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
27 } while (false)
29 namespace gfx { class Rect; }
31 namespace cc {
32 class LayerImpl;
33 class OutputSurface;
34 class QuadList;
35 class RenderSurfaceImpl;
36 class ResourceProvider;
38 class LayerTestCommon {
39 public:
40 static const char* quad_string;
42 static void VerifyQuadsExactlyCoverRect(const QuadList& quads,
43 const gfx::Rect& rect);
45 static void VerifyQuadsAreOccluded(const QuadList& quads,
46 const gfx::Rect& occluded,
47 size_t* partially_occluded_count);
49 class LayerImplTest {
50 public:
51 LayerImplTest();
52 explicit LayerImplTest(const LayerTreeSettings& settings);
53 ~LayerImplTest();
55 template <typename T>
56 T* AddChildToRoot() {
57 scoped_ptr<T> layer =
58 T::Create(host_->host_impl()->active_tree(), layer_impl_id_++);
59 T* ptr = layer.get();
60 root_layer_impl_->AddChild(layer.Pass());
61 return ptr;
64 template <typename T>
65 T* AddChild(LayerImpl* parent) {
66 scoped_ptr<T> layer =
67 T::Create(host_->host_impl()->active_tree(), layer_impl_id_++);
68 T* ptr = layer.get();
69 parent->AddChild(layer.Pass());
70 return ptr;
73 template <typename T, typename A>
74 T* AddChildToRoot(const A& a) {
75 scoped_ptr<T> layer =
76 T::Create(host_->host_impl()->active_tree(), layer_impl_id_++, a);
77 T* ptr = layer.get();
78 root_layer_impl_->AddChild(layer.Pass());
79 return ptr;
82 template <typename T, typename A, typename B>
83 T* AddChildToRoot(const A& a, const B& b) {
84 scoped_ptr<T> layer =
85 T::Create(host_->host_impl()->active_tree(), layer_impl_id_++, a, b);
86 T* ptr = layer.get();
87 root_layer_impl_->AddChild(layer.Pass());
88 return ptr;
91 template <typename T, typename A, typename B, typename C, typename D>
92 T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
93 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(),
94 layer_impl_id_++, a, b, c, d);
95 T* ptr = layer.get();
96 root_layer_impl_->AddChild(layer.Pass());
97 return ptr;
100 template <typename T,
101 typename A,
102 typename B,
103 typename C,
104 typename D,
105 typename E>
106 T* AddChildToRoot(const A& a,
107 const B& b,
108 const C& c,
109 const D& d,
110 const E& e) {
111 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(),
112 layer_impl_id_++, a, b, c, d, e);
113 T* ptr = layer.get();
114 root_layer_impl_->AddChild(layer.Pass());
115 return ptr;
118 void CalcDrawProps(const gfx::Size& viewport_size);
119 void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
120 const gfx::Rect& occluded);
121 void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
122 RenderPass* given_render_pass,
123 const gfx::Rect& occluded);
124 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
125 const gfx::Rect& occluded);
127 OutputSurface* output_surface() const {
128 return host_->host_impl()->output_surface();
130 ResourceProvider* resource_provider() const {
131 return host_->host_impl()->resource_provider();
133 LayerImpl* root_layer() const { return root_layer_impl_.get(); }
134 FakeLayerTreeHost* host() { return host_.get(); }
135 FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
136 Proxy* proxy() const { return host_->host_impl()->proxy(); }
137 const QuadList& quad_list() const { return render_pass_->quad_list; }
139 private:
140 FakeLayerTreeHostClient client_;
141 TestTaskGraphRunner task_graph_runner_;
142 scoped_ptr<FakeLayerTreeHost> host_;
143 scoped_ptr<LayerImpl> root_layer_impl_;
144 scoped_ptr<RenderPass> render_pass_;
145 int layer_impl_id_;
149 } // namespace cc
151 #endif // CC_TEST_LAYER_TEST_COMMON_H_