OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CCThreadedTest_h | 5 // Temporary forwarding header |
6 #define CCThreadedTest_h | 6 #include "cc/threaded_unittest.h" |
7 | |
8 #include "CCLayerTreeHost.h" | |
9 #include "CCLayerTreeHostImpl.h" | |
10 #include "CCScopedThreadProxy.h" | |
11 #include "CompositorFakeWebGraphicsContext3D.h" | |
12 #include "base/hash_tables.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 #include <public/WebAnimationDelegate.h> | |
15 #include <public/WebThread.h> | |
16 | |
17 namespace cc { | |
18 class CCLayerImpl; | |
19 class CCLayerTreeHost; | |
20 class CCLayerTreeHostClient; | |
21 class CCLayerTreeHostImpl; | |
22 class GraphicsContext3D; | |
23 } | |
24 | |
25 namespace WebKitTests { | |
26 | |
27 // Used by test stubs to notify the test when something interesting happens. | |
28 class TestHooks : public WebKit::WebAnimationDelegate { | |
29 public: | |
30 virtual void beginCommitOnCCThread(cc::CCLayerTreeHostImpl*) { } | |
31 virtual void commitCompleteOnCCThread(cc::CCLayerTreeHostImpl*) { } | |
32 virtual bool prepareToDrawOnCCThread(cc::CCLayerTreeHostImpl*); | |
33 virtual void drawLayersOnCCThread(cc::CCLayerTreeHostImpl*) { } | |
34 virtual void animateLayers(cc::CCLayerTreeHostImpl*, double monotonicTime) {
} | |
35 virtual void willAnimateLayers(cc::CCLayerTreeHostImpl*, double monotonicTim
e) { } | |
36 virtual void applyScrollAndScale(const cc::IntSize&, float) { } | |
37 virtual void animate(double monotonicTime) { } | |
38 virtual void layout() { } | |
39 virtual void didRecreateOutputSurface(bool succeeded) { } | |
40 virtual void didAddAnimation() { } | |
41 virtual void didCommit() { } | |
42 virtual void didCommitAndDrawFrame() { } | |
43 virtual void scheduleComposite() { } | |
44 | |
45 // Implementation of WebAnimationDelegate | |
46 virtual void notifyAnimationStarted(double time) OVERRIDE { } | |
47 virtual void notifyAnimationFinished(double time) OVERRIDE { } | |
48 | |
49 virtual scoped_ptr<WebKit::WebCompositorOutputSurface> createOutputSurface()
; | |
50 }; | |
51 | |
52 class TimeoutTask; | |
53 class BeginTask; | |
54 | |
55 class MockCCLayerTreeHostClient : public cc::CCLayerTreeHostClient { | |
56 }; | |
57 | |
58 // The CCThreadedTests runs with the main loop running. It instantiates a single
MockLayerTreeHost and associated | |
59 // MockLayerTreeHostImpl/MockLayerTreeHostClient. | |
60 // | |
61 // beginTest() is called once the main message loop is running and the layer tre
e host is initialized. | |
62 // | |
63 // Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCThre
adedTest methods of similar names. | |
64 // To track the commit process, override these functions. | |
65 // | |
66 // The test continues until someone calls endTest. endTest can be called on any
thread, but be aware that | |
67 // ending the test is an asynchronous process. | |
68 class CCThreadedTest : public testing::Test, public TestHooks { | |
69 public: | |
70 virtual ~CCThreadedTest(); | |
71 | |
72 virtual void afterTest() = 0; | |
73 virtual void beginTest() = 0; | |
74 | |
75 void endTest(); | |
76 void endTestAfterDelay(int delayMilliseconds); | |
77 | |
78 void postSetNeedsAnimateToMainThread(); | |
79 void postAddAnimationToMainThread(); | |
80 void postAddInstantAnimationToMainThread(); | |
81 void postSetNeedsCommitToMainThread(); | |
82 void postAcquireLayerTextures(); | |
83 void postSetNeedsRedrawToMainThread(); | |
84 void postSetNeedsAnimateAndCommitToMainThread(); | |
85 void postSetVisibleToMainThread(bool visible); | |
86 void postDidAddAnimationToMainThread(); | |
87 | |
88 void doBeginTest(); | |
89 void timeout(); | |
90 | |
91 void clearTimeout() { m_timeoutTask = 0; } | |
92 | |
93 cc::CCLayerTreeHost* layerTreeHost() { return m_layerTreeHost.get(); } | |
94 | |
95 protected: | |
96 CCThreadedTest(); | |
97 | |
98 virtual void initializeSettings(cc::CCLayerTreeSettings&) { } | |
99 | |
100 virtual void scheduleComposite() OVERRIDE; | |
101 | |
102 void realEndTest(); | |
103 | |
104 void dispatchSetNeedsAnimate(); | |
105 void dispatchAddInstantAnimation(); | |
106 void dispatchAddAnimation(); | |
107 void dispatchSetNeedsAnimateAndCommit(); | |
108 void dispatchSetNeedsCommit(); | |
109 void dispatchAcquireLayerTextures(); | |
110 void dispatchSetNeedsRedraw(); | |
111 void dispatchSetVisible(bool); | |
112 void dispatchComposite(); | |
113 void dispatchDidAddAnimation(); | |
114 | |
115 virtual void runTest(bool threaded); | |
116 WebKit::WebThread* webThread() const { return m_webThread.get(); } | |
117 | |
118 cc::CCLayerTreeSettings m_settings; | |
119 OwnPtr<MockCCLayerTreeHostClient> m_client; | |
120 scoped_ptr<cc::CCLayerTreeHost> m_layerTreeHost; | |
121 | |
122 protected: | |
123 RefPtr<cc::CCScopedThreadProxy> m_mainThreadProxy; | |
124 | |
125 private: | |
126 bool m_beginning; | |
127 bool m_endWhenBeginReturns; | |
128 bool m_timedOut; | |
129 bool m_finished; | |
130 bool m_scheduled; | |
131 bool m_started; | |
132 | |
133 OwnPtr<WebKit::WebThread> m_webThread; | |
134 TimeoutTask* m_timeoutTask; | |
135 BeginTask* m_beginTask; | |
136 }; | |
137 | |
138 class CCThreadedTestThreadOnly : public CCThreadedTest { | |
139 public: | |
140 void runTestThreaded() | |
141 { | |
142 CCThreadedTest::runTest(true); | |
143 } | |
144 }; | |
145 | |
146 // Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks. | |
147 class MockLayerTreeHostImpl : public cc::CCLayerTreeHostImpl { | |
148 public: | |
149 static scoped_ptr<MockLayerTreeHostImpl> create(TestHooks*, const cc::CCLaye
rTreeSettings&, cc::CCLayerTreeHostImplClient*); | |
150 | |
151 virtual void beginCommit() OVERRIDE; | |
152 virtual void commitComplete() OVERRIDE; | |
153 virtual bool prepareToDraw(FrameData&) OVERRIDE; | |
154 virtual void drawLayers(const FrameData&) OVERRIDE; | |
155 | |
156 // Make these public. | |
157 typedef std::vector<cc::CCLayerImpl*> CCLayerList; | |
158 using CCLayerTreeHostImpl::calculateRenderSurfaceLayerList; | |
159 | |
160 protected: | |
161 virtual void animateLayers(double monotonicTime, double wallClockTime) OVERR
IDE; | |
162 virtual base::TimeDelta lowFrequencyAnimationInterval() const OVERRIDE; | |
163 | |
164 private: | |
165 MockLayerTreeHostImpl(TestHooks*, const cc::CCLayerTreeSettings&, cc::CCLaye
rTreeHostImplClient*); | |
166 | |
167 TestHooks* m_testHooks; | |
168 }; | |
169 | |
170 class CompositorFakeWebGraphicsContext3DWithTextureTracking : public WebKit::Com
positorFakeWebGraphicsContext3D { | |
171 public: | |
172 static PassOwnPtr<CompositorFakeWebGraphicsContext3DWithTextureTracking> cre
ate(Attributes); | |
173 virtual ~CompositorFakeWebGraphicsContext3DWithTextureTracking(); | |
174 | |
175 virtual WebKit::WebGLId createTexture(); | |
176 | |
177 virtual void deleteTexture(WebKit::WebGLId texture); | |
178 | |
179 virtual void bindTexture(WebKit::WGC3Denum target, WebKit::WebGLId texture); | |
180 | |
181 int numTextures() const; | |
182 int texture(int texture) const; | |
183 void resetTextures(); | |
184 | |
185 int numUsedTextures() const; | |
186 bool usedTexture(int texture) const; | |
187 void resetUsedTextures(); | |
188 | |
189 private: | |
190 explicit CompositorFakeWebGraphicsContext3DWithTextureTracking(Attributes at
trs); | |
191 | |
192 Vector<WebKit::WebGLId> m_textures; | |
193 base::hash_set<WebKit::WebGLId> m_usedTextures; | |
194 }; | |
195 | |
196 } // namespace WebKitTests | |
197 | |
198 #define SINGLE_AND_MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | |
199 TEST_F(TEST_FIXTURE_NAME, runSingleThread) \ | |
200 { \ | |
201 runTest(false); \ | |
202 } \ | |
203 TEST_F(TEST_FIXTURE_NAME, runMultiThread) \ | |
204 { \ | |
205 runTest(true); \ | |
206 } | |
207 | |
208 #endif // CCThreadedTest_h | |
OLD | NEW |