Adding binary files for platform_keys tests.
[chromium-blink-merge.git] / cc / test / layer_test_common.h
blobdfd9729d01a93a06943cfe912048ddcaa48b87ec
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/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 VerifyQuadsAreOccluded(const QuadList& quads,
45 const gfx::Rect& occluded,
46 size_t* partially_occluded_count);
48 class LayerImplTest {
49 public:
50 LayerImplTest();
51 ~LayerImplTest();
53 template <typename T>
54 T* AddChildToRoot() {
55 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2);
56 T* ptr = layer.get();
57 root_layer_impl_->AddChild(layer.Pass());
58 return ptr;
61 template <typename T, typename A>
62 T* AddChildToRoot(const A& a) {
63 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2, a);
64 T* ptr = layer.get();
65 root_layer_impl_->AddChild(layer.Pass());
66 return ptr;
69 template <typename T, typename A, typename B>
70 T* AddChildToRoot(const A& a, const B& b) {
71 scoped_ptr<T> layer =
72 T::Create(host_->host_impl()->active_tree(), 2, a, b);
73 T* ptr = layer.get();
74 root_layer_impl_->AddChild(layer.Pass());
75 return ptr;
78 template <typename T, typename A, typename B, typename C, typename D>
79 T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
80 scoped_ptr<T> layer =
81 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d);
82 T* ptr = layer.get();
83 root_layer_impl_->AddChild(layer.Pass());
84 return ptr;
87 template <typename T,
88 typename A,
89 typename B,
90 typename C,
91 typename D,
92 typename E>
93 T* AddChildToRoot(const A& a,
94 const B& b,
95 const C& c,
96 const D& d,
97 const E& e) {
98 scoped_ptr<T> layer =
99 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d, e);
100 T* ptr = layer.get();
101 root_layer_impl_->AddChild(layer.Pass());
102 return ptr;
105 void CalcDrawProps(const gfx::Size& viewport_size);
106 void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
107 const gfx::Rect& occluded);
108 void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
109 RenderPass* given_render_pass,
110 const gfx::Rect& occluded);
111 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
112 const gfx::Rect& occluded);
114 OutputSurface* output_surface() const {
115 return host_->host_impl()->output_surface();
117 ResourceProvider* resource_provider() const {
118 return host_->host_impl()->resource_provider();
120 LayerImpl* root_layer() const { return root_layer_impl_.get(); }
121 FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
122 Proxy* proxy() const { return host_->host_impl()->proxy(); }
123 const QuadList& quad_list() const { return render_pass_->quad_list; }
125 private:
126 FakeLayerTreeHostClient client_;
127 scoped_ptr<FakeLayerTreeHost> host_;
128 scoped_ptr<LayerImpl> root_layer_impl_;
129 scoped_ptr<RenderPass> render_pass_;
133 } // namespace cc
135 #endif // CC_TEST_LAYER_TEST_COMMON_H_