[DevTools] Remove unused moveWindowBy embedder message.
[chromium-blink-merge.git] / cc / test / layer_test_common.h
blob5ff96efb725649febec4abdb4dfee30287ff4096
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/mock_occlusion_tracker.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 ~LayerImplTest();
54 template <typename T>
55 T* AddChildToRoot() {
56 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2);
57 T* ptr = layer.get();
58 root_layer_impl_->AddChild(layer.Pass());
59 return ptr;
62 template <typename T, typename A>
63 T* AddChildToRoot(const A& a) {
64 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2, a);
65 T* ptr = layer.get();
66 root_layer_impl_->AddChild(layer.Pass());
67 return ptr;
70 template <typename T, typename A, typename B>
71 T* AddChildToRoot(const A& a, const B& b) {
72 scoped_ptr<T> layer =
73 T::Create(host_->host_impl()->active_tree(), 2, a, b);
74 T* ptr = layer.get();
75 root_layer_impl_->AddChild(layer.Pass());
76 return ptr;
79 template <typename T, typename A, typename B, typename C, typename D>
80 T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
81 scoped_ptr<T> layer =
82 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d);
83 T* ptr = layer.get();
84 root_layer_impl_->AddChild(layer.Pass());
85 return ptr;
88 template <typename T,
89 typename A,
90 typename B,
91 typename C,
92 typename D,
93 typename E>
94 T* AddChildToRoot(const A& a,
95 const B& b,
96 const C& c,
97 const D& d,
98 const E& e) {
99 scoped_ptr<T> layer =
100 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d, e);
101 T* ptr = layer.get();
102 root_layer_impl_->AddChild(layer.Pass());
103 return ptr;
106 void CalcDrawProps(const gfx::Size& viewport_size);
107 void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
108 const gfx::Rect& occluded);
109 void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
110 const RenderPassId& id,
111 const gfx::Rect& occluded);
112 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
113 const gfx::Rect& occluded);
115 OutputSurface* output_surface() const {
116 return host_->host_impl()->output_surface();
118 ResourceProvider* resource_provider() const {
119 return host_->host_impl()->resource_provider();
121 LayerImpl* root_layer() const { return root_layer_impl_.get(); }
122 FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
123 Proxy* proxy() const { return host_->host_impl()->proxy(); }
124 const QuadList& quad_list() const { return render_pass_->quad_list; }
126 private:
127 FakeLayerTreeHostClient client_;
128 scoped_ptr<FakeLayerTreeHost> host_;
129 scoped_ptr<LayerImpl> root_layer_impl_;
130 scoped_ptr<RenderPass> render_pass_;
131 MockOcclusionTracker<LayerImpl> occlusion_tracker_;
135 } // namespace cc
137 #endif // CC_TEST_LAYER_TEST_COMMON_H_