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) \
16 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times((expect)); \
18 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
21 #define EXPECT_SET_NEEDS_UPDATE(expect, code_to_test) \
23 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times((expect)); \
25 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \
28 namespace gfx
{ class Rect
; }
34 class RenderSurfaceImpl
;
35 class ResourceProvider
;
37 class LayerTestCommon
{
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
);
55 scoped_ptr
<T
> layer
= T::Create(host_
->host_impl()->active_tree(), 2);
57 root_layer_impl_
->AddChild(layer
.Pass());
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
);
65 root_layer_impl_
->AddChild(layer
.Pass());
69 template <typename T
, typename A
, typename B
>
70 T
* AddChildToRoot(const A
& a
, const B
& b
) {
72 T::Create(host_
->host_impl()->active_tree(), 2, a
, b
);
74 root_layer_impl_
->AddChild(layer
.Pass());
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
) {
81 T::Create(host_
->host_impl()->active_tree(), 2, a
, b
, c
, d
);
83 root_layer_impl_
->AddChild(layer
.Pass());
93 T
* AddChildToRoot(const A
& a
,
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());
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
; }
126 FakeLayerTreeHostClient client_
;
127 scoped_ptr
<FakeLayerTreeHost
> host_
;
128 scoped_ptr
<LayerImpl
> root_layer_impl_
;
129 scoped_ptr
<RenderPass
> render_pass_
;
135 #endif // CC_TEST_LAYER_TEST_COMMON_H_