| 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/base/thread.h" | 10 #include "cc/base/thread.h" |
| 11 #include "cc/trees/layer_tree_host.h" | 11 #include "cc/trees/layer_tree_host.h" |
| 12 #include "cc/trees/layer_tree_host_impl.h" | 12 #include "cc/trees/layer_tree_host_impl.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat
e.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat
e.h" |
| 15 | 15 |
| 16 namespace Webkit { | 16 namespace Webkit { |
| 17 class WebGraphicsContext3D; | 17 class WebGraphicsContext3D; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 class FakeContextProvider; |
| 21 class FakeLayerTreeHostClient; | 22 class FakeLayerTreeHostClient; |
| 22 class LayerImpl; | 23 class LayerImpl; |
| 23 class LayerTreeHost; | 24 class LayerTreeHost; |
| 24 class LayerTreeHostClient; | 25 class LayerTreeHostClient; |
| 25 class LayerTreeHostImpl; | 26 class LayerTreeHostImpl; |
| 26 | 27 |
| 27 // Used by test stubs to notify the test when something interesting happens. | 28 // Used by test stubs to notify the test when something interesting happens. |
| 28 class TestHooks : public WebKit::WebAnimationDelegate { | 29 class TestHooks : public WebKit::WebAnimationDelegate { |
| 29 public: | 30 public: |
| 30 TestHooks(); | 31 TestHooks(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 virtual void ScheduleComposite() {} | 63 virtual void ScheduleComposite() {} |
| 63 virtual void DidDeferCommit() {} | 64 virtual void DidDeferCommit() {} |
| 64 virtual bool CanActivatePendingTree(); | 65 virtual bool CanActivatePendingTree(); |
| 65 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, | 66 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl, |
| 66 bool visible) {} | 67 bool visible) {} |
| 67 | 68 |
| 68 // Implementation of WebAnimationDelegate | 69 // Implementation of WebAnimationDelegate |
| 69 virtual void notifyAnimationStarted(double time) OVERRIDE {} | 70 virtual void notifyAnimationStarted(double time) OVERRIDE {} |
| 70 virtual void notifyAnimationFinished(double time) OVERRIDE {} | 71 virtual void notifyAnimationFinished(double time) OVERRIDE {} |
| 71 | 72 |
| 72 virtual scoped_ptr<OutputSurface> CreateOutputSurface(); | 73 virtual scoped_ptr<OutputSurface> CreateOutputSurface() = 0; |
| 73 | |
| 74 virtual scoped_refptr<cc::ContextProvider> | 74 virtual scoped_refptr<cc::ContextProvider> |
| 75 OffscreenContextProviderForMainThread(); | 75 OffscreenContextProviderForMainThread() = 0; |
| 76 virtual scoped_refptr<cc::ContextProvider> | 76 virtual scoped_refptr<cc::ContextProvider> |
| 77 OffscreenContextProviderForCompositorThread(); | 77 OffscreenContextProviderForCompositorThread() = 0; |
| 78 | |
| 79 private: | |
| 80 scoped_ptr<FakeLayerTreeHostClient> fake_client_; | |
| 81 }; | 78 }; |
| 82 | 79 |
| 83 class BeginTask; | 80 class BeginTask; |
| 84 class LayerTreeHostClientForTesting; | 81 class LayerTreeHostClientForTesting; |
| 85 class TimeoutTask; | 82 class TimeoutTask; |
| 86 | 83 |
| 87 // The LayerTreeTests runs with the main loop running. It instantiates a single | 84 // The LayerTreeTests runs with the main loop running. It instantiates a single |
| 88 // LayerTreeHostForTesting and associated LayerTreeHostImplForTesting and | 85 // LayerTreeHostForTesting and associated LayerTreeHostImplForTesting and |
| 89 // LayerTreeHostClientForTesting. | 86 // LayerTreeHostClientForTesting. |
| 90 // | 87 // |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation); | 128 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation); |
| 132 virtual void DispatchAddAnimation(Layer* layer_to_receive_animation); | 129 virtual void DispatchAddAnimation(Layer* layer_to_receive_animation); |
| 133 void DispatchSetNeedsCommit(); | 130 void DispatchSetNeedsCommit(); |
| 134 void DispatchAcquireLayerTextures(); | 131 void DispatchAcquireLayerTextures(); |
| 135 void DispatchSetNeedsRedraw(); | 132 void DispatchSetNeedsRedraw(); |
| 136 void DispatchSetNeedsRedrawRect(gfx::Rect damage_rect); | 133 void DispatchSetNeedsRedrawRect(gfx::Rect damage_rect); |
| 137 void DispatchSetVisible(bool visible); | 134 void DispatchSetVisible(bool visible); |
| 138 void DispatchComposite(); | 135 void DispatchComposite(); |
| 139 void DispatchDidAddAnimation(); | 136 void DispatchDidAddAnimation(); |
| 140 | 137 |
| 141 virtual void RunTest(bool threaded); | 138 virtual void RunTest(bool threaded, bool delegating_renderer); |
| 142 | 139 |
| 143 Thread* ImplThread() { return proxy() ? proxy()->ImplThread() : NULL; } | 140 Thread* ImplThread() { return proxy() ? proxy()->ImplThread() : NULL; } |
| 144 Proxy* proxy() const { | 141 Proxy* proxy() const { |
| 145 return layer_tree_host_ ? layer_tree_host_->proxy() : NULL; | 142 return layer_tree_host_ ? layer_tree_host_->proxy() : NULL; |
| 146 } | 143 } |
| 147 | 144 |
| 148 bool TestEnded() const { return ended_; } | 145 bool TestEnded() const { return ended_; } |
| 149 | 146 |
| 150 LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); } | 147 LayerTreeHost* layer_tree_host() { return layer_tree_host_.get(); } |
| 148 bool delegating_renderer() const { return delegating_renderer_; } |
| 149 |
| 150 virtual scoped_ptr<OutputSurface> CreateOutputSurface() OVERRIDE; |
| 151 virtual scoped_refptr<cc::ContextProvider> |
| 152 OffscreenContextProviderForMainThread() OVERRIDE; |
| 153 virtual scoped_refptr<cc::ContextProvider> |
| 154 OffscreenContextProviderForCompositorThread() OVERRIDE; |
| 151 | 155 |
| 152 private: | 156 private: |
| 153 LayerTreeSettings settings_; | 157 LayerTreeSettings settings_; |
| 154 scoped_ptr<LayerTreeHostClientForTesting> client_; | 158 scoped_ptr<LayerTreeHostClientForTesting> client_; |
| 155 scoped_ptr<LayerTreeHost> layer_tree_host_; | 159 scoped_ptr<LayerTreeHost> layer_tree_host_; |
| 156 | 160 |
| 157 bool beginning_; | 161 bool beginning_; |
| 158 bool end_when_begin_returns_; | 162 bool end_when_begin_returns_; |
| 159 bool timed_out_; | 163 bool timed_out_; |
| 160 bool scheduled_; | 164 bool scheduled_; |
| 161 bool schedule_when_set_visible_true_; | 165 bool schedule_when_set_visible_true_; |
| 162 bool started_; | 166 bool started_; |
| 163 bool ended_; | 167 bool ended_; |
| 168 bool delegating_renderer_; |
| 164 | 169 |
| 165 int timeout_seconds_; | 170 int timeout_seconds_; |
| 166 | 171 |
| 167 scoped_ptr<Thread> main_ccthread_; | 172 scoped_ptr<Thread> main_ccthread_; |
| 168 scoped_ptr<base::Thread> impl_thread_; | 173 scoped_ptr<base::Thread> impl_thread_; |
| 169 base::CancelableClosure timeout_; | 174 base::CancelableClosure timeout_; |
| 170 base::WeakPtr<LayerTreeTest> main_thread_weak_ptr_; | 175 base::WeakPtr<LayerTreeTest> main_thread_weak_ptr_; |
| 171 base::WeakPtrFactory<LayerTreeTest> weak_factory_; | 176 base::WeakPtrFactory<LayerTreeTest> weak_factory_; |
| 177 scoped_refptr<FakeContextProvider> main_thread_contexts_; |
| 178 scoped_refptr<FakeContextProvider> compositor_thread_contexts_; |
| 172 }; | 179 }; |
| 173 | 180 |
| 174 } // namespace cc | 181 } // namespace cc |
| 175 | 182 |
| 176 #define SINGLE_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 183 #define SINGLE_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME) \ |
| 177 TEST_F(TEST_FIXTURE_NAME, RunSingleThread) { \ | 184 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DirectRenderer) { \ |
| 178 RunTest(false); \ | 185 RunTest(false, false); \ |
| 179 } \ | 186 } \ |
| 180 class SingleThreadNeedsSemicolon##TEST_FIXTURE_NAME {} | 187 class SingleThreadDirectNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 181 | 188 |
| 189 #define SINGLE_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME) \ |
| 190 TEST_F(TEST_FIXTURE_NAME, RunSingleThread_DelegatingRenderer) { \ |
| 191 RunTest(false, true); \ |
| 192 } \ |
| 193 class SingleThreadDelegatingNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 182 | 194 |
| 183 #define MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 195 #define SINGLE_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
| 184 TEST_F(TEST_FIXTURE_NAME, RunMultiThread) { \ | 196 SINGLE_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME); \ |
| 185 RunTest(true); \ | 197 SINGLE_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME) |
| 186 } \ | 198 |
| 187 class MultiThreadNeedsSemicolon##TEST_FIXTURE_NAME {} | 199 #define MULTI_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME) \ |
| 200 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DirectRenderer) { \ |
| 201 RunTest(true, false); \ |
| 202 } \ |
| 203 class MultiThreadDirectNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 204 |
| 205 #define MULTI_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME) \ |
| 206 TEST_F(TEST_FIXTURE_NAME, RunMultiThread_DelegatingRenderer) { \ |
| 207 RunTest(true, true); \ |
| 208 } \ |
| 209 class MultiThreadDelegatingNeedsSemicolon##TEST_FIXTURE_NAME {} |
| 210 |
| 211 #define MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
| 212 MULTI_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME); \ |
| 213 MULTI_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME) |
| 214 |
| 215 #define SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
| 216 SINGLE_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME); \ |
| 217 MULTI_THREAD_TEST_DIRECT_RENDERER_F(TEST_FIXTURE_NAME) |
| 218 |
| 219 #define SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) \ |
| 220 SINGLE_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME); \ |
| 221 MULTI_THREAD_TEST_DELEGATING_RENDERER_F(TEST_FIXTURE_NAME) |
| 188 | 222 |
| 189 #define SINGLE_AND_MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ | 223 #define SINGLE_AND_MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) \ |
| 190 SINGLE_THREAD_TEST_F(TEST_FIXTURE_NAME); \ | 224 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TEST_FIXTURE_NAME); \ |
| 191 MULTI_THREAD_TEST_F(TEST_FIXTURE_NAME) | 225 SINGLE_AND_MULTI_THREAD_DELEGATING_RENDERER_TEST_F(TEST_FIXTURE_NAME) |
| 192 | 226 |
| 193 #endif // CC_TEST_LAYER_TREE_TEST_H_ | 227 #endif // CC_TEST_LAYER_TREE_TEST_H_ |
| OLD | NEW |