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) \
17 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
19 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
22 #define EXPECT_SET_NEEDS_UPDATE(expect, code_to_test) \
24 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times((expect)); \
26 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
29 namespace gfx
{ class Rect
; }
35 class RenderSurfaceImpl
;
36 class ResourceProvider
;
38 class LayerTestCommon
{
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
);
57 T::Create(host_
->host_impl()->active_tree(), layer_impl_id_
++);
59 root_layer_impl_
->AddChild(layer
.Pass());
64 T
* AddChild(LayerImpl
* parent
) {
66 T::Create(host_
->host_impl()->active_tree(), layer_impl_id_
++);
68 parent
->AddChild(layer
.Pass());
72 template <typename T
, typename A
>
73 T
* AddChildToRoot(const A
& a
) {
75 T::Create(host_
->host_impl()->active_tree(), layer_impl_id_
++, a
);
77 root_layer_impl_
->AddChild(layer
.Pass());
81 template <typename T
, typename A
, typename B
>
82 T
* AddChildToRoot(const A
& a
, const B
& b
) {
84 T::Create(host_
->host_impl()->active_tree(), layer_impl_id_
++, a
, b
);
86 root_layer_impl_
->AddChild(layer
.Pass());
90 template <typename T
, typename A
, typename B
, typename C
, typename D
>
91 T
* AddChildToRoot(const A
& a
, const B
& b
, const C
& c
, const D
& d
) {
92 scoped_ptr
<T
> layer
= T::Create(host_
->host_impl()->active_tree(),
93 layer_impl_id_
++, a
, b
, c
, d
);
95 root_layer_impl_
->AddChild(layer
.Pass());
105 T
* AddChildToRoot(const A
& a
,
110 scoped_ptr
<T
> layer
= T::Create(host_
->host_impl()->active_tree(),
111 layer_impl_id_
++, a
, b
, c
, d
, e
);
112 T
* ptr
= layer
.get();
113 root_layer_impl_
->AddChild(layer
.Pass());
117 void CalcDrawProps(const gfx::Size
& viewport_size
);
118 void AppendQuadsWithOcclusion(LayerImpl
* layer_impl
,
119 const gfx::Rect
& occluded
);
120 void AppendQuadsForPassWithOcclusion(LayerImpl
* layer_impl
,
121 RenderPass
* given_render_pass
,
122 const gfx::Rect
& occluded
);
123 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl
* surface_impl
,
124 const gfx::Rect
& occluded
);
126 OutputSurface
* output_surface() const {
127 return host_
->host_impl()->output_surface();
129 ResourceProvider
* resource_provider() const {
130 return host_
->host_impl()->resource_provider();
132 LayerImpl
* root_layer() const { return root_layer_impl_
.get(); }
133 FakeLayerTreeHost
* host() { return host_
.get(); }
134 FakeLayerTreeHostImpl
* host_impl() const { return host_
->host_impl(); }
135 Proxy
* proxy() const { return host_
->host_impl()->proxy(); }
136 const QuadList
& quad_list() const { return render_pass_
->quad_list
; }
139 FakeLayerTreeHostClient client_
;
140 TestTaskGraphRunner task_graph_runner_
;
141 scoped_ptr
<FakeLayerTreeHost
> host_
;
142 scoped_ptr
<LayerImpl
> root_layer_impl_
;
143 scoped_ptr
<RenderPass
> render_pass_
;
150 #endif // CC_TEST_LAYER_TEST_COMMON_H_