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) \
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 VerifyQuadsCoverRectWithOcclusion(
45 const QuadList
& quads
,
46 const gfx::Rect
& rect
,
47 const gfx::Rect
& occluded
,
48 size_t* partially_occluded_count
);
57 scoped_ptr
<T
> layer
= T::Create(host_
->host_impl()->active_tree(), 2);
59 root_layer_impl_
->AddChild(layer
.template PassAs
<LayerImpl
>());
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
);
67 root_layer_impl_
->AddChild(layer
.template PassAs
<LayerImpl
>());
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
) {
74 T::Create(host_
->host_impl()->active_tree(), 2, a
, b
, c
, d
);
76 root_layer_impl_
->AddChild(layer
.template PassAs
<LayerImpl
>());
86 T
* AddChildToRoot(const A
& a
,
92 T::Create(host_
->host_impl()->active_tree(), 2, a
, b
, c
, d
, e
);
94 root_layer_impl_
->AddChild(layer
.template PassAs
<LayerImpl
>());
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(); }
119 scoped_ptr
<FakeLayerTreeHost
> host_
;
120 scoped_ptr
<LayerImpl
> root_layer_impl_
;
121 MockQuadCuller quad_culler_
;
127 #endif // CC_TEST_LAYER_TEST_COMMON_H_