• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "cc/test/layer_tree_test.h"
8 #include "cc/trees/thread_proxy.h"
9 
10 #define THREAD_PROXY_NO_IMPL_TEST_F(TEST_FIXTURE_NAME) \
11   TEST_F(TEST_FIXTURE_NAME, Run_MainThreadPaint) {     \
12     Run(true, false);                                  \
13   }
14 
15 #define THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME)    \
16   THREAD_PROXY_NO_IMPL_TEST_F(TEST_FIXTURE_NAME); \
17   TEST_F(TEST_FIXTURE_NAME, Run_ImplSidePaint) {  \
18     Run(true, true);                              \
19   }
20 
21 // Do common tests for single thread proxy and thread proxy.
22 // TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F
23 #define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \
24   THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME);
25 
26 namespace cc {
27 
28 class ProxyTest : public LayerTreeTest {
29  protected:
ProxyTest()30   ProxyTest() {}
~ProxyTest()31   virtual ~ProxyTest() {}
32 
Run(bool threaded,bool impl_side_painting)33   void Run(bool threaded, bool impl_side_painting) {
34     // We don't need to care about delegating mode.
35     bool delegating_renderer = true;
36 
37     RunTest(threaded, delegating_renderer, impl_side_painting);
38   }
39 
BeginTest()40   virtual void BeginTest() OVERRIDE {}
AfterTest()41   virtual void AfterTest() OVERRIDE {}
42 
43  private:
44   DISALLOW_COPY_AND_ASSIGN(ProxyTest);
45 };
46 
47 class ProxyTestScheduledActionsBasic : public ProxyTest {
48  protected:
BeginTest()49   virtual void BeginTest() OVERRIDE {
50     proxy()->SetNeedsCommit();
51   }
52 
ScheduledActionBeginOutputSurfaceCreation()53   virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {
54     EXPECT_EQ(0, action_phase_++);
55   }
56 
ScheduledActionSendBeginMainFrame()57   virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {
58     EXPECT_EQ(1, action_phase_++);
59   }
60 
ScheduledActionCommit()61   virtual void ScheduledActionCommit() OVERRIDE {
62     EXPECT_EQ(2, action_phase_++);
63   }
64 
ScheduledActionDrawAndSwapIfPossible()65   virtual void ScheduledActionDrawAndSwapIfPossible() OVERRIDE {
66     EXPECT_EQ(3, action_phase_++);
67     EndTest();
68   }
69 
AfterTest()70   virtual void AfterTest() OVERRIDE {
71     EXPECT_EQ(4, action_phase_);
72   }
73 
ProxyTestScheduledActionsBasic()74   ProxyTestScheduledActionsBasic() : action_phase_(0) {
75   }
~ProxyTestScheduledActionsBasic()76   virtual ~ProxyTestScheduledActionsBasic() {}
77 
78  private:
79   int action_phase_;
80 
81   DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic);
82 };
83 
84 PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic);
85 
86 class ThreadProxyTest : public ProxyTest {
87  protected:
ThreadProxyTest()88   ThreadProxyTest() {}
~ThreadProxyTest()89   virtual ~ThreadProxyTest() {}
90 
ThreadProxyMainOnly() const91   const ThreadProxy::MainThreadOnly& ThreadProxyMainOnly() const {
92     DCHECK(proxy());
93     DCHECK(proxy()->HasImplThread());
94     return static_cast<const ThreadProxy*>(proxy())->main();
95   }
96 
ThreadProxyImplOnly() const97   const ThreadProxy::CompositorThreadOnly& ThreadProxyImplOnly() const {
98     DCHECK(proxy());
99     DCHECK(proxy()->HasImplThread());
100     return static_cast<const ThreadProxy*>(proxy())->impl();
101   }
102 
103  private:
104   DISALLOW_COPY_AND_ASSIGN(ThreadProxyTest);
105 };
106 
107 class ThreadProxyTestSetNeedsCommit : public ThreadProxyTest {
108  protected:
ThreadProxyTestSetNeedsCommit()109   ThreadProxyTestSetNeedsCommit() {}
~ThreadProxyTestSetNeedsCommit()110   virtual ~ThreadProxyTestSetNeedsCommit() {}
111 
BeginTest()112   virtual void BeginTest() OVERRIDE {
113     EXPECT_FALSE(ThreadProxyMainOnly().commit_requested);
114     EXPECT_FALSE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread);
115 
116     proxy()->SetNeedsCommit();
117 
118     EXPECT_TRUE(ThreadProxyMainOnly().commit_requested);
119     EXPECT_TRUE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread);
120   }
121 
DidBeginMainFrame()122   virtual void DidBeginMainFrame() OVERRIDE {
123     EXPECT_FALSE(ThreadProxyMainOnly().commit_requested);
124     EXPECT_FALSE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread);
125 
126     EndTest();
127   }
128 
129  private:
130   DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsCommit);
131 };
132 
133 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsCommit);
134 
135 }  // namespace cc
136