OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 CC_TEST_LAYER_TREE_TEST_H_ | 5 #ifndef CC_TEST_LAYER_TREE_TEST_H_ |
6 #define CC_TEST_LAYER_TREE_TEST_H_ | 6 #define CC_TEST_LAYER_TREE_TEST_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "cc/animation/animation_delegate.h" | 10 #include "cc/animation/animation_delegate.h" |
11 #include "cc/layers/layer_settings.h" | 11 #include "cc/layers/layer_settings.h" |
12 #include "cc/test/proxy_impl_for_test.h" | 12 #include "cc/test/proxy_impl_for_test.h" |
13 #include "cc/test/proxy_main_for_test.h" | 13 #include "cc/test/proxy_main_for_test.h" |
| 14 #include "cc/test/remote_proto_channel_bridge.h" |
14 #include "cc/test/test_hooks.h" | 15 #include "cc/test/test_hooks.h" |
15 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
16 #include "cc/trees/layer_tree_host_impl.h" | 17 #include "cc/trees/layer_tree_host_impl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 class AnimationPlayer; | 21 class AnimationPlayer; |
21 class FakeExternalBeginFrameSource; | 22 class FakeExternalBeginFrameSource; |
22 class FakeLayerTreeHostClient; | 23 class FakeLayerTreeHostClient; |
23 class FakeOutputSurface; | 24 class FakeOutputSurface; |
24 class LayerImpl; | 25 class LayerImpl; |
25 class LayerTreeHost; | 26 class LayerTreeHost; |
| 27 class LayerTreeHostForTesting; |
26 class LayerTreeHostClient; | 28 class LayerTreeHostClient; |
27 class LayerTreeHostImpl; | 29 class LayerTreeHostImpl; |
| 30 class RemoteChannelImplForTest; |
28 class TestContextProvider; | 31 class TestContextProvider; |
29 class TestGpuMemoryBufferManager; | 32 class TestGpuMemoryBufferManager; |
30 class TestTaskGraphRunner; | 33 class TestTaskGraphRunner; |
31 class TestWebGraphicsContext3D; | 34 class TestWebGraphicsContext3D; |
| 35 class ThreadedChannelForTest; |
32 | 36 |
33 // Creates the virtual viewport layer hierarchy under the given root_layer. | 37 // Creates the virtual viewport layer hierarchy under the given root_layer. |
34 // Convenient overload of the method below that creates a scrolling layer as | 38 // Convenient overload of the method below that creates a scrolling layer as |
35 // the outer viewport scroll layer. | 39 // the outer viewport scroll layer. |
36 void CreateVirtualViewportLayers(Layer* root_layer, | 40 void CreateVirtualViewportLayers(Layer* root_layer, |
37 const gfx::Size& inner_bounds, | 41 const gfx::Size& inner_bounds, |
38 const gfx::Size& outer_bounds, | 42 const gfx::Size& outer_bounds, |
39 const gfx::Size& scroll_bounds, | 43 const gfx::Size& scroll_bounds, |
40 LayerTreeHost* host, | 44 LayerTreeHost* host, |
41 const LayerSettings& layer_settings); | 45 const LayerSettings& layer_settings); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void DispatchSetNextCommitForcesRedraw(); | 128 void DispatchSetNextCommitForcesRedraw(); |
125 void DispatchDidAddAnimation(); | 129 void DispatchDidAddAnimation(); |
126 void DispatchCompositeImmediately(); | 130 void DispatchCompositeImmediately(); |
127 void DispatchNextCommitWaitsForActivation(); | 131 void DispatchNextCommitWaitsForActivation(); |
128 | 132 |
129 virtual void AfterTest() = 0; | 133 virtual void AfterTest() = 0; |
130 virtual void WillBeginTest(); | 134 virtual void WillBeginTest(); |
131 virtual void BeginTest() = 0; | 135 virtual void BeginTest() = 0; |
132 virtual void SetupTree(); | 136 virtual void SetupTree(); |
133 | 137 |
134 // TODO(khushalsagar): Add mode for running remote channel tests. | |
135 virtual void RunTest(CompositorMode mode, bool delegating_renderer); | 138 virtual void RunTest(CompositorMode mode, bool delegating_renderer); |
136 | 139 |
137 bool HasImplThread() const { return !!impl_thread_; } | 140 bool HasImplThread() const { return !!impl_thread_; } |
138 base::SingleThreadTaskRunner* ImplThreadTaskRunner() { | 141 base::SingleThreadTaskRunner* ImplThreadTaskRunner() { |
139 DCHECK(task_runner_provider()); | 142 DCHECK(task_runner_provider()); |
140 base::SingleThreadTaskRunner* impl_thread_task_runner = | 143 base::SingleThreadTaskRunner* impl_thread_task_runner = |
141 task_runner_provider()->ImplThreadTaskRunner(); | 144 task_runner_provider()->ImplThreadTaskRunner(); |
142 return impl_thread_task_runner ? impl_thread_task_runner | 145 return impl_thread_task_runner ? impl_thread_task_runner |
143 : main_task_runner_.get(); | 146 : main_task_runner_.get(); |
144 } | 147 } |
145 base::SingleThreadTaskRunner* MainThreadTaskRunner() { | 148 base::SingleThreadTaskRunner* MainThreadTaskRunner() { |
146 return main_task_runner_.get(); | 149 return main_task_runner_.get(); |
147 } | 150 } |
148 Proxy* proxy() const { | 151 Proxy* proxy() const { |
149 return layer_tree_host_ ? layer_tree_host_->proxy() : NULL; | 152 return layer_tree_host_ ? layer_tree_host_->proxy() : NULL; |
150 } | 153 } |
151 TaskRunnerProvider* task_runner_provider() const { | 154 Proxy* remote_client_proxy() const; |
152 return layer_tree_host_ ? layer_tree_host_->task_runner_provider() | 155 TaskRunnerProvider* task_runner_provider() const; |
153 : nullptr; | |
154 } | |
155 TaskGraphRunner* task_graph_runner() const; | 156 TaskGraphRunner* task_graph_runner() const; |
156 bool TestEnded() const { return ended_; } | 157 bool TestEnded() const { return ended_; } |
157 | 158 |
158 LayerTreeHost* layer_tree_host(); | 159 LayerTreeHost* layer_tree_host(); |
159 bool delegating_renderer() const { return delegating_renderer_; } | 160 bool delegating_renderer() const { return delegating_renderer_; } |
160 FakeOutputSurface* output_surface() { return output_surface_; } | 161 FakeOutputSurface* output_surface() { return output_surface_; } |
161 int LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) const; | 162 int LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) const; |
162 | 163 |
163 // Use these only for ProxyMain tests in threaded mode. | 164 // Use these only for tests in threaded or remote mode. |
164 // TODO(khushalsagar): Update these when adding support for remote channel | |
165 // tests. | |
166 ProxyMainForTest* GetProxyMainForTest() const; | 165 ProxyMainForTest* GetProxyMainForTest() const; |
167 ProxyImplForTest* GetProxyImplForTest() const; | 166 ProxyImplForTest* GetProxyImplForTest() const; |
168 | 167 |
| 168 // Use this only for tests in threaded mode. |
| 169 ThreadedChannelForTest* GetThreadedChannelForTest() const; |
| 170 |
| 171 // Use this only for tests in remote mode. |
| 172 RemoteChannelImplForTest* GetRemoteChannelImplForTest() const; |
| 173 |
169 void DestroyLayerTreeHost(); | 174 void DestroyLayerTreeHost(); |
| 175 void DestroyRemoteClientHost() override; |
| 176 |
| 177 void CreateRemoteClientHost( |
| 178 const proto::CompositorMessageToImpl& proto) override; |
170 | 179 |
171 // By default, output surface recreation is synchronous. | 180 // By default, output surface recreation is synchronous. |
172 void RequestNewOutputSurface() override; | 181 void RequestNewOutputSurface() override; |
173 // Override this for pixel tests, where you need a real output surface. | 182 // Override this for pixel tests, where you need a real output surface. |
174 virtual scoped_ptr<OutputSurface> CreateOutputSurface(); | 183 virtual scoped_ptr<OutputSurface> CreateOutputSurface(); |
175 // Override this for unit tests, which should not produce pixel output. | 184 // Override this for unit tests, which should not produce pixel output. |
176 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(); | 185 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(); |
177 | 186 |
178 TestWebGraphicsContext3D* TestContext(); | 187 TestWebGraphicsContext3D* TestContext(); |
179 | 188 |
180 TestGpuMemoryBufferManager* GetTestGpuMemoryBufferManager() { | 189 TestGpuMemoryBufferManager* GetTestGpuMemoryBufferManager() { |
181 return gpu_memory_buffer_manager_.get(); | 190 return gpu_memory_buffer_manager_.get(); |
182 } | 191 } |
183 | 192 |
| 193 bool IsRemoteTest() const; |
| 194 |
184 private: | 195 private: |
185 LayerTreeSettings settings_; | 196 LayerTreeSettings settings_; |
186 LayerSettings layer_settings_; | 197 LayerSettings layer_settings_; |
187 | 198 |
188 CompositorMode mode_; | 199 CompositorMode mode_; |
189 | 200 |
190 scoped_ptr<LayerTreeHostClientForTesting> client_; | 201 scoped_ptr<LayerTreeHostClientForTesting> client_; |
191 scoped_ptr<LayerTreeHost> layer_tree_host_; | 202 scoped_ptr<LayerTreeHost> layer_tree_host_; |
| 203 |
| 204 // The LayerTreeHost created by the cc embedder on the client in remote mode. |
| 205 scoped_ptr<LayerTreeHostForTesting> remote_client_layer_tree_host_; |
| 206 |
192 FakeOutputSurface* output_surface_; | 207 FakeOutputSurface* output_surface_; |
193 FakeExternalBeginFrameSource* external_begin_frame_source_; | 208 FakeExternalBeginFrameSource* external_begin_frame_source_; |
| 209 RemoteProtoChannelBridge remote_proto_channel_bridge_; |
194 | 210 |
195 bool beginning_; | 211 bool beginning_; |
196 bool end_when_begin_returns_; | 212 bool end_when_begin_returns_; |
197 bool timed_out_; | 213 bool timed_out_; |
198 bool scheduled_; | 214 bool scheduled_; |
199 bool started_; | 215 bool started_; |
200 bool ended_; | 216 bool ended_; |
201 bool delegating_renderer_; | 217 bool delegating_renderer_; |
202 bool verify_property_trees_; | 218 bool verify_property_trees_; |
203 | 219 |
204 int timeout_seconds_; | 220 int timeout_seconds_; |
205 | 221 |
206 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 222 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
207 scoped_ptr<base::Thread> impl_thread_; | 223 scoped_ptr<base::Thread> impl_thread_; |
208 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 224 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
209 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 225 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
210 scoped_ptr<TestTaskGraphRunner> task_graph_runner_; | 226 scoped_ptr<TestTaskGraphRunner> task_graph_runner_; |
211 base::CancelableClosure timeout_; | 227 base::CancelableClosure timeout_; |
212 scoped_refptr<TestContextProvider> compositor_contexts_; | 228 scoped_refptr<TestContextProvider> compositor_contexts_; |
213 base::WeakPtr<LayerTreeTest> main_thread_weak_ptr_; | 229 base::WeakPtr<LayerTreeTest> main_thread_weak_ptr_; |
214 base::WeakPtrFactory<LayerTreeTest> weak_factory_; | 230 base::WeakPtrFactory<LayerTreeTest> weak_factory_; |
215 }; | 231 }; |
216 | 232 |
217 } // namespace cc | 233 } // namespace cc |
218 | 234 |
219 #define SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 235 #define SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
220 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DirectRenderer) { \ | 236 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DirectRenderer) { \ |
221 RunTest(CompositorMode::SingleThreaded, false); \ | 237 RunTest(CompositorMode::SINGLE_THREADED, false); \ |
222 } \ | 238 } \ |
223 class SingleThreadDirectImplNeedsSemicolon##TEST_FIXTURE_NAME {} | 239 class SingleThreadDirectImplNeedsSemicolon##TEST_FIXTURE_NAME {} |
224 | 240 |
225 #define SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 241 #define SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
226 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DelegatingRenderer) { \ | 242 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DelegatingRenderer) { \ |
227 RunTest(CompositorMode::SingleThreaded, true); \ | 243 RunTest(CompositorMode::SINGLE_THREADED, true); \ |
228 } \ | 244 } \ |
229 class SingleThreadDelegatingImplNeedsSemicolon##TEST_FIXTURE_NAME {} | 245 class SingleThreadDelegatingImplNeedsSemicolon##TEST_FIXTURE_NAME {} |
230 | 246 |
231 #define SINGLE_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 247 #define SINGLE_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
232 SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ | 248 SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
233 SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) | 249 SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
234 | 250 |
235 #define MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 251 #define MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
236 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DirectRenderer) { \ | 252 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DirectRenderer) { \ |
237 RunTest(CompositorMode::Threaded, false); \ | 253 RunTest(CompositorMode::THREADED, false); \ |
238 } \ | 254 } \ |
239 class MultiThreadDirectImplNeedsSemicolon##TEST_FIXTURE_NAME {} | 255 class MultiThreadDirectImplNeedsSemicolon##TEST_FIXTURE_NAME {} |
240 | 256 |
241 #define MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 257 #define MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
242 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DelegatingRenderer) { \ | 258 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DelegatingRenderer) { \ |
243 RunTest(CompositorMode::Threaded, true); \ | 259 RunTest(CompositorMode::THREADED, true); \ |
244 } \ | 260 } \ |
245 class MultiThreadDelegatingImplNeedsSemicolon##TEST_FIXTURE_NAME {} | 261 class MultiThreadDelegatingImplNeedsSemicolon##TEST_FIXTURE_NAME {} |
246 | 262 |
247 #define MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 263 #define MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
248 MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ | 264 MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
249 MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) | 265 MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
250 | 266 |
| 267 // The Remote mode tests don't need to run for delegated renderer. |
| 268 #define REMOTE_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
| 269 TEST_F(TEST_FIXTURE_NAME, RunRemote_DirectRenderer) { \ |
| 270 RunTest(CompositorMode::REMOTE, false); \ |
| 271 } \ |
| 272 class RemoteDirectImplNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 273 |
251 #define SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 274 #define SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
252 SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ | 275 SINGLE_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
253 MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) | 276 MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
254 | 277 |
255 #define SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ | 278 #define SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
256 SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ | 279 SINGLE_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
257 MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) | 280 MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
258 | 281 |
259 #define SINGLE_AND_MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 282 #define SINGLE_AND_MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
260 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ | 283 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
261 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) | 284 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
262 | 285 |
263 // Some tests want to control when notify ready for activation occurs, | 286 // Some tests want to control when notify ready for activation occurs, |
264 // but this is not supported in the single-threaded case. | 287 // but this is not supported in the single-threaded case. |
265 #define MULTI_THREAD_BLOCKNOTIFY_TEST_F(TEST_FIXTURE_NAME) \ | 288 #define MULTI_THREAD_BLOCKNOTIFY_TEST_F(TEST_FIXTURE_NAME) \ |
266 MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) | 289 MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) |
267 | 290 |
268 #endif // CC_TEST_LAYER_TREE_TEST_H_ | 291 #endif // CC_TEST_LAYER_TREE_TEST_H_ |
OLD | NEW |