This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_proxy.cc
blobd4057cfa10a2a17ba9f8f246f4be0e4a3bda724a
1 // Copyright 2014 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 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "cc/test/fake_content_layer_client.h"
8 #include "cc/test/fake_picture_layer.h"
9 #include "cc/test/layer_tree_test.h"
10 #include "cc/trees/thread_proxy.h"
12 #define THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME) \
13 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); }
15 // Do common tests for single thread proxy and thread proxy.
16 // TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F
17 #define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \
18 THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME);
20 namespace cc {
22 class ProxyTest : public LayerTreeTest {
23 protected:
24 ProxyTest() {}
25 ~ProxyTest() override {}
27 void Run(bool threaded) {
28 // We don't need to care about delegating mode.
29 bool delegating_renderer = true;
31 RunTest(threaded, delegating_renderer);
34 void BeginTest() override {}
35 void AfterTest() override {}
37 private:
38 DISALLOW_COPY_AND_ASSIGN(ProxyTest);
41 class ProxyTestScheduledActionsBasic : public ProxyTest {
42 protected:
43 void BeginTest() override { proxy()->SetNeedsCommit(); }
45 void ScheduledActionBeginOutputSurfaceCreation() override {
46 EXPECT_EQ(0, action_phase_++);
49 void ScheduledActionSendBeginMainFrame() override {
50 EXPECT_EQ(1, action_phase_++);
53 void ScheduledActionCommit() override { EXPECT_EQ(2, action_phase_++); }
55 void ScheduledActionDrawAndSwapIfPossible() override {
56 EXPECT_EQ(3, action_phase_++);
57 EndTest();
60 void AfterTest() override { EXPECT_EQ(4, action_phase_); }
62 ProxyTestScheduledActionsBasic() : action_phase_(0) {
64 ~ProxyTestScheduledActionsBasic() override {}
66 private:
67 int action_phase_;
69 DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic);
72 PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic);
74 class ThreadProxyTest : public ProxyTest {
75 protected:
76 ThreadProxyTest()
77 : update_check_layer_(
78 FakePictureLayer::Create(layer_settings(), &client_)) {}
79 ~ThreadProxyTest() override {}
81 void SetupTree() override {
82 layer_tree_host()->SetRootLayer(update_check_layer_);
83 ProxyTest::SetupTree();
86 const ThreadProxy::MainThreadOnly& ThreadProxyMainOnly() const {
87 DCHECK(proxy());
88 DCHECK(proxy()->HasImplThread());
89 return static_cast<const ThreadProxy*>(proxy())->main();
92 const ThreadProxy::CompositorThreadOnly& ThreadProxyImplOnly() const {
93 DCHECK(proxy());
94 DCHECK(proxy()->HasImplThread());
95 return static_cast<const ThreadProxy*>(proxy())->impl();
98 protected:
99 FakeContentLayerClient client_;
100 scoped_refptr<FakePictureLayer> update_check_layer_;
102 private:
103 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTest);
106 class ThreadProxyTestSetNeedsCommit : public ThreadProxyTest {
107 protected:
108 ThreadProxyTestSetNeedsCommit() {}
109 ~ThreadProxyTestSetNeedsCommit() override {}
111 void BeginTest() override {
112 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
113 ThreadProxyMainOnly().max_requested_pipeline_stage);
115 proxy()->SetNeedsCommit();
117 EXPECT_EQ(ThreadProxy::COMMIT_PIPELINE_STAGE,
118 ThreadProxyMainOnly().max_requested_pipeline_stage);
121 void DidBeginMainFrame() override {
122 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
123 ThreadProxyMainOnly().max_requested_pipeline_stage);
124 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
125 ThreadProxyMainOnly().current_pipeline_stage);
128 void DidCommit() override {
129 EXPECT_EQ(1, update_check_layer_->update_count());
130 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
131 ThreadProxyMainOnly().current_pipeline_stage);
132 EndTest();
135 private:
136 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsCommit);
139 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsCommit);
141 class ThreadProxyTestSetNeedsAnimate : public ThreadProxyTest {
142 protected:
143 ThreadProxyTestSetNeedsAnimate() {}
144 ~ThreadProxyTestSetNeedsAnimate() override {}
146 void BeginTest() override {
147 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
148 ThreadProxyMainOnly().max_requested_pipeline_stage);
150 proxy()->SetNeedsAnimate();
152 EXPECT_EQ(ThreadProxy::ANIMATE_PIPELINE_STAGE,
153 ThreadProxyMainOnly().max_requested_pipeline_stage);
156 void DidBeginMainFrame() override {
157 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
158 ThreadProxyMainOnly().max_requested_pipeline_stage);
159 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
160 ThreadProxyMainOnly().current_pipeline_stage);
163 void DidCommit() override {
164 EXPECT_EQ(0, update_check_layer_->update_count());
165 EndTest();
168 private:
169 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsAnimate);
172 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsAnimate);
174 class ThreadProxyTestSetNeedsUpdateLayers : public ThreadProxyTest {
175 protected:
176 ThreadProxyTestSetNeedsUpdateLayers() {}
177 ~ThreadProxyTestSetNeedsUpdateLayers() override {}
179 void BeginTest() override {
180 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
181 ThreadProxyMainOnly().max_requested_pipeline_stage);
183 proxy()->SetNeedsUpdateLayers();
185 EXPECT_EQ(ThreadProxy::UPDATE_LAYERS_PIPELINE_STAGE,
186 ThreadProxyMainOnly().max_requested_pipeline_stage);
189 void DidBeginMainFrame() override {
190 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
191 ThreadProxyMainOnly().max_requested_pipeline_stage);
192 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
193 ThreadProxyMainOnly().current_pipeline_stage);
196 void DidCommit() override {
197 EXPECT_EQ(1, update_check_layer_->update_count());
198 EndTest();
201 private:
202 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsUpdateLayers);
205 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsUpdateLayers);
207 class ThreadProxyTestSetNeedsUpdateLayersWhileAnimating
208 : public ThreadProxyTest {
209 protected:
210 ThreadProxyTestSetNeedsUpdateLayersWhileAnimating() {}
211 ~ThreadProxyTestSetNeedsUpdateLayersWhileAnimating() override {}
213 void BeginTest() override { proxy()->SetNeedsAnimate(); }
215 void WillBeginMainFrame() override {
216 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
217 ThreadProxyMainOnly().max_requested_pipeline_stage);
218 EXPECT_EQ(ThreadProxy::ANIMATE_PIPELINE_STAGE,
219 ThreadProxyMainOnly().current_pipeline_stage);
220 EXPECT_EQ(ThreadProxy::ANIMATE_PIPELINE_STAGE,
221 ThreadProxyMainOnly().final_pipeline_stage);
223 proxy()->SetNeedsUpdateLayers();
225 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
226 ThreadProxyMainOnly().max_requested_pipeline_stage);
227 EXPECT_EQ(ThreadProxy::UPDATE_LAYERS_PIPELINE_STAGE,
228 ThreadProxyMainOnly().final_pipeline_stage);
231 void DidBeginMainFrame() override {
232 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
233 ThreadProxyMainOnly().max_requested_pipeline_stage);
234 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
235 ThreadProxyMainOnly().current_pipeline_stage);
238 void DidCommit() override {
239 EXPECT_EQ(1, update_check_layer_->update_count());
240 EndTest();
243 private:
244 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsUpdateLayersWhileAnimating);
247 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsUpdateLayersWhileAnimating);
249 class ThreadProxyTestSetNeedsCommitWhileAnimating : public ThreadProxyTest {
250 protected:
251 ThreadProxyTestSetNeedsCommitWhileAnimating() {}
252 ~ThreadProxyTestSetNeedsCommitWhileAnimating() override {}
254 void BeginTest() override { proxy()->SetNeedsAnimate(); }
256 void WillBeginMainFrame() override {
257 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
258 ThreadProxyMainOnly().max_requested_pipeline_stage);
259 EXPECT_EQ(ThreadProxy::ANIMATE_PIPELINE_STAGE,
260 ThreadProxyMainOnly().current_pipeline_stage);
261 EXPECT_EQ(ThreadProxy::ANIMATE_PIPELINE_STAGE,
262 ThreadProxyMainOnly().final_pipeline_stage);
264 proxy()->SetNeedsCommit();
266 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
267 ThreadProxyMainOnly().max_requested_pipeline_stage);
268 EXPECT_EQ(ThreadProxy::COMMIT_PIPELINE_STAGE,
269 ThreadProxyMainOnly().final_pipeline_stage);
272 void DidBeginMainFrame() override {
273 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
274 ThreadProxyMainOnly().max_requested_pipeline_stage);
275 EXPECT_EQ(ThreadProxy::NO_PIPELINE_STAGE,
276 ThreadProxyMainOnly().current_pipeline_stage);
279 void DidCommit() override {
280 EXPECT_EQ(1, update_check_layer_->update_count());
281 EndTest();
284 private:
285 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsCommitWhileAnimating);
288 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsCommitWhileAnimating);
290 } // namespace cc