Adds initial key systems support for Chromecast.
[chromium-blink-merge.git] / cc / test / layer_test_common.h
blobc8e6ba5c66e1efbef6aebabca3edf815d180594a
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 VerifyQuadsCoverRectWithOcclusion(
46 const QuadList& quads,
47 const gfx::Rect& rect,
48 const gfx::Rect& occluded,
49 size_t* partially_occluded_count);
51 class LayerImplTest {
52 public:
53 LayerImplTest();
54 ~LayerImplTest();
56 template <typename T>
57 T* AddChildToRoot() {
58 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2);
59 T* ptr = layer.get();
60 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
61 return ptr;
64 template <typename T, typename A>
65 T* AddChildToRoot(const A& a) {
66 scoped_ptr<T> layer = T::Create(host_->host_impl()->active_tree(), 2, a);
67 T* ptr = layer.get();
68 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
69 return ptr;
72 template <typename T, typename A, typename B>
73 T* AddChildToRoot(const A& a, const B& b) {
74 scoped_ptr<T> layer =
75 T::Create(host_->host_impl()->active_tree(), 2, a, b);
76 T* ptr = layer.get();
77 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
78 return ptr;
81 template <typename T, typename A, typename B, typename C, typename D>
82 T* AddChildToRoot(const A& a, const B& b, const C& c, const D& d) {
83 scoped_ptr<T> layer =
84 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d);
85 T* ptr = layer.get();
86 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
87 return ptr;
90 template <typename T,
91 typename A,
92 typename B,
93 typename C,
94 typename D,
95 typename E>
96 T* AddChildToRoot(const A& a,
97 const B& b,
98 const C& c,
99 const D& d,
100 const E& e) {
101 scoped_ptr<T> layer =
102 T::Create(host_->host_impl()->active_tree(), 2, a, b, c, d, e);
103 T* ptr = layer.get();
104 root_layer_impl_->AddChild(layer.template PassAs<LayerImpl>());
105 return ptr;
108 void CalcDrawProps(const gfx::Size& viewport_size);
109 void AppendQuadsWithOcclusion(LayerImpl* layer_impl,
110 const gfx::Rect& occluded);
111 void AppendQuadsForPassWithOcclusion(LayerImpl* layer_impl,
112 const RenderPassId& id,
113 const gfx::Rect& occluded);
114 void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
115 const gfx::Rect& occluded);
117 OutputSurface* output_surface() const {
118 return host_->host_impl()->output_surface();
120 ResourceProvider* resource_provider() const {
121 return host_->host_impl()->resource_provider();
123 LayerImpl* root_layer() const { return root_layer_impl_.get(); }
124 FakeLayerTreeHostImpl* host_impl() const { return host_->host_impl(); }
125 Proxy* proxy() const { return host_->host_impl()->proxy(); }
126 const QuadList& quad_list() const { return render_pass_->quad_list; }
128 private:
129 scoped_ptr<FakeLayerTreeHost> host_;
130 scoped_ptr<LayerImpl> root_layer_impl_;
131 scoped_ptr<RenderPass> render_pass_;
132 MockOcclusionTracker<LayerImpl> occlusion_tracker_;
136 } // namespace cc
138 #endif // CC_TEST_LAYER_TEST_COMMON_H_