Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / cc / test / layer_test_common.h
blobee7d1328b232855391095093d3daad45299808b1
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/test/fake_layer_tree_host.h"
11 #include "cc/test/mock_quad_culler.h"
12 #include "cc/trees/layer_tree_host_impl.h"
14 #define EXPECT_SET_NEEDS_COMMIT(expect, code_to_test) \
15 do { \
16 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
17 code_to_test; \
18 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
19 } while (false)
21 #define EXPECT_SET_NEEDS_UPDATE(expect, code_to_test) \
22 do { \
23 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times((expect)); \
24 code_to_test; \
25 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
26 } while (false)
28 namespace gfx { class Rect; }
30 namespace cc {
31 class LayerImpl;
32 class OutputSurface;
33 class QuadList;
34 class RenderSurfaceImpl;
35 class ResourceProvider;
37 class LayerTestCommon {
38 public:
39 static const char* quad_string;
41 static void VerifyQuadsExactlyCoverRect(const QuadList& quads,
42 const gfx::Rect& rect);
44 static void VerifyQuadsCoverRectWithOcclusion(
45 const QuadList& quads,
46 const gfx::Rect& rect,
47 const gfx::Rect& occluded,
48 size_t* partially_occluded_count);
50 class LayerImplTest {
51 public:
52 LayerImplTest();
53 ~LayerImplTest();
55 template <typename T>
56 T* AddChildToRoot() {
57 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2);
58 T* ptr = layer.get();
59 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
60 return ptr;
63 template <typename T, typename A>
64 T* AddChildToRoot(const A& a) {
65 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2, a);
66 T* ptr = layer.get();
67 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
68 return ptr;
71 template <typename T, typename A, typename B, typename C, typename D>
72 T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
73 scoped_ptr<T> layer =
74 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d);
75 T* ptr = layer.get();
76 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
77 return ptr;
80 template <typename T,
81 typename A,
82 typename B,
83 typename C,
84 typename D,
85 typename E>
86 T* AddChildToRoot(const A& a,
87 const B& b,
88 const C& c,
89 const D& d,
90 const E& e) {
91 scoped_ptr<T> layer =
92 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d, e);
93 T* ptr = layer.get();
94 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
95 return ptr;
98 void CalcDrawProps(const gfx::Size& viewport_size);
99 void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
100 const gfx::Rect& occluded);
101 void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
102 const RenderPass::Id& id,
103 const gfx::Rect& occluded);
104 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
105 const gfx::Rect& occluded);
107 OutputSurface* output_surface() const {
108 return host_->host_impl()->output_surface();
110 ResourceProvider* resource_provider() const {
111 return host_->host_impl()->resource_provider();
113 LayerImpl* root_layer() const { return root_layer_impl_.get(); }
114 FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
115 Proxy* proxy() const { return host_->host_impl()->proxy(); }
116 const QuadList& quad_list() const { return quad_culler_.quad_list(); }
118 private:
119 scoped_ptr<FakeLayerTreeHost> host_;
120 scoped_ptr<LayerImpl> root_layer_impl_;
121 MockQuadCuller quad_culler_;
125 } // namespace cc
127 #endif // CC_TEST_LAYER_TEST_COMMON_H_