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 CCThreadedTest_h | 5 #ifndef CCThreadedTest_h |
6 #define CCThreadedTest_h | 6 #define CCThreadedTest_h |
7 | 7 |
8 #include "CCLayerTreeHost.h" | 8 #include "CCLayerTreeHost.h" |
9 #include "CCLayerTreeHostImpl.h" | 9 #include "CCLayerTreeHostImpl.h" |
10 #include "CCScopedThreadProxy.h" | 10 #include "CCScopedThreadProxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class GraphicsContext3D; | 21 class GraphicsContext3D; |
22 } | 22 } |
23 | 23 |
24 namespace WebKitTests { | 24 namespace WebKitTests { |
25 | 25 |
26 // Used by test stubs to notify the test when something interesting happens. | 26 // Used by test stubs to notify the test when something interesting happens. |
27 class TestHooks : public WebKit::WebAnimationDelegate { | 27 class TestHooks : public WebKit::WebAnimationDelegate { |
28 public: | 28 public: |
29 virtual void beginCommitOnCCThread(cc::CCLayerTreeHostImpl*) { } | 29 virtual void beginCommitOnCCThread(cc::CCLayerTreeHostImpl*) { } |
30 virtual void commitCompleteOnCCThread(cc::CCLayerTreeHostImpl*) { } | 30 virtual void commitCompleteOnCCThread(cc::CCLayerTreeHostImpl*) { } |
31 virtual bool prepareToDrawOnCCThread(cc::CCLayerTreeHostImpl*) { return true
; } | 31 virtual bool prepareToDrawOnCCThread(cc::CCLayerTreeHostImpl*); |
32 virtual void drawLayersOnCCThread(cc::CCLayerTreeHostImpl*) { } | 32 virtual void drawLayersOnCCThread(cc::CCLayerTreeHostImpl*) { } |
33 virtual void animateLayers(cc::CCLayerTreeHostImpl*, double monotonicTime) {
} | 33 virtual void animateLayers(cc::CCLayerTreeHostImpl*, double monotonicTime) {
} |
34 virtual void willAnimateLayers(cc::CCLayerTreeHostImpl*, double monotonicTim
e) { } | 34 virtual void willAnimateLayers(cc::CCLayerTreeHostImpl*, double monotonicTim
e) { } |
35 virtual void applyScrollAndScale(const cc::IntSize&, float) { } | 35 virtual void applyScrollAndScale(const cc::IntSize&, float) { } |
36 virtual void animate(double monotonicTime) { } | 36 virtual void animate(double monotonicTime) { } |
37 virtual void layout() { } | 37 virtual void layout() { } |
38 virtual void didRecreateOutputSurface(bool succeeded) { } | 38 virtual void didRecreateOutputSurface(bool succeeded) { } |
39 virtual void didAddAnimation() { } | 39 virtual void didAddAnimation() { } |
40 virtual void didCommit() { } | 40 virtual void didCommit() { } |
41 virtual void didCommitAndDrawFrame() { } | 41 virtual void didCommitAndDrawFrame() { } |
(...skipping 17 matching lines...) Expand all Loading... |
59 // | 59 // |
60 // beginTest() is called once the main message loop is running and the layer tre
e host is initialized. | 60 // beginTest() is called once the main message loop is running and the layer tre
e host is initialized. |
61 // | 61 // |
62 // Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCThre
adedTest methods of similar names. | 62 // Key stages of the drawing loop, e.g. drawing or commiting, redirect to CCThre
adedTest methods of similar names. |
63 // To track the commit process, override these functions. | 63 // To track the commit process, override these functions. |
64 // | 64 // |
65 // The test continues until someone calls endTest. endTest can be called on any
thread, but be aware that | 65 // The test continues until someone calls endTest. endTest can be called on any
thread, but be aware that |
66 // ending the test is an asynchronous process. | 66 // ending the test is an asynchronous process. |
67 class CCThreadedTest : public testing::Test, public TestHooks { | 67 class CCThreadedTest : public testing::Test, public TestHooks { |
68 public: | 68 public: |
| 69 virtual ~CCThreadedTest(); |
| 70 |
69 virtual void afterTest() = 0; | 71 virtual void afterTest() = 0; |
70 virtual void beginTest() = 0; | 72 virtual void beginTest() = 0; |
71 | 73 |
72 void endTest(); | 74 void endTest(); |
73 void endTestAfterDelay(int delayMilliseconds); | 75 void endTestAfterDelay(int delayMilliseconds); |
74 | 76 |
75 void postSetNeedsAnimateToMainThread(); | 77 void postSetNeedsAnimateToMainThread(); |
76 void postAddAnimationToMainThread(); | 78 void postAddAnimationToMainThread(); |
77 void postAddInstantAnimationToMainThread(); | 79 void postAddInstantAnimationToMainThread(); |
78 void postSetNeedsCommitToMainThread(); | 80 void postSetNeedsCommitToMainThread(); |
79 void postAcquireLayerTextures(); | 81 void postAcquireLayerTextures(); |
80 void postSetNeedsRedrawToMainThread(); | 82 void postSetNeedsRedrawToMainThread(); |
81 void postSetNeedsAnimateAndCommitToMainThread(); | 83 void postSetNeedsAnimateAndCommitToMainThread(); |
82 void postSetVisibleToMainThread(bool visible); | 84 void postSetVisibleToMainThread(bool visible); |
83 void postDidAddAnimationToMainThread(); | 85 void postDidAddAnimationToMainThread(); |
84 | 86 |
85 void doBeginTest(); | 87 void doBeginTest(); |
86 void timeout(); | 88 void timeout(); |
87 | 89 |
88 void clearTimeout() { m_timeoutTask = 0; } | 90 void clearTimeout() { m_timeoutTask = 0; } |
89 | 91 |
90 cc::CCLayerTreeHost* layerTreeHost() { return m_layerTreeHost.get(); } | 92 cc::CCLayerTreeHost* layerTreeHost() { return m_layerTreeHost.get(); } |
91 | 93 |
92 protected: | 94 protected: |
93 CCThreadedTest(); | 95 CCThreadedTest(); |
94 | 96 |
95 virtual void initializeSettings(cc::CCLayerTreeSettings&) { } | 97 virtual void initializeSettings(cc::CCLayerTreeSettings&) { } |
96 | 98 |
97 virtual void scheduleComposite(); | 99 virtual void scheduleComposite() OVERRIDE; |
98 | 100 |
99 void realEndTest(); | 101 void realEndTest(); |
100 | 102 |
101 void dispatchSetNeedsAnimate(); | 103 void dispatchSetNeedsAnimate(); |
102 void dispatchAddInstantAnimation(); | 104 void dispatchAddInstantAnimation(); |
103 void dispatchAddAnimation(); | 105 void dispatchAddAnimation(); |
104 void dispatchSetNeedsAnimateAndCommit(); | 106 void dispatchSetNeedsAnimateAndCommit(); |
105 void dispatchSetNeedsCommit(); | 107 void dispatchSetNeedsCommit(); |
106 void dispatchAcquireLayerTextures(); | 108 void dispatchAcquireLayerTextures(); |
107 void dispatchSetNeedsRedraw(); | 109 void dispatchSetNeedsRedraw(); |
(...skipping 30 matching lines...) Expand all Loading... |
138 { | 140 { |
139 CCThreadedTest::runTest(true); | 141 CCThreadedTest::runTest(true); |
140 } | 142 } |
141 }; | 143 }; |
142 | 144 |
143 // Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks. | 145 // Adapts CCLayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
144 class MockLayerTreeHostImpl : public cc::CCLayerTreeHostImpl { | 146 class MockLayerTreeHostImpl : public cc::CCLayerTreeHostImpl { |
145 public: | 147 public: |
146 static PassOwnPtr<MockLayerTreeHostImpl> create(TestHooks*, const cc::CCLaye
rTreeSettings&, cc::CCLayerTreeHostImplClient*); | 148 static PassOwnPtr<MockLayerTreeHostImpl> create(TestHooks*, const cc::CCLaye
rTreeSettings&, cc::CCLayerTreeHostImplClient*); |
147 | 149 |
148 virtual void beginCommit(); | 150 virtual void beginCommit() OVERRIDE; |
149 virtual void commitComplete(); | 151 virtual void commitComplete() OVERRIDE; |
150 virtual bool prepareToDraw(FrameData&); | 152 virtual bool prepareToDraw(FrameData&) OVERRIDE; |
151 virtual void drawLayers(const FrameData&); | 153 virtual void drawLayers(const FrameData&) OVERRIDE; |
152 | 154 |
153 // Make these public. | 155 // Make these public. |
154 typedef Vector<cc::CCLayerImpl*> CCLayerList; | 156 typedef Vector<cc::CCLayerImpl*> CCLayerList; |
155 using CCLayerTreeHostImpl::calculateRenderSurfaceLayerList; | 157 using CCLayerTreeHostImpl::calculateRenderSurfaceLayerList; |
156 | 158 |
157 protected: | 159 protected: |
158 virtual void animateLayers(double monotonicTime, double wallClockTime); | 160 virtual void animateLayers(double monotonicTime, double wallClockTime) OVERR
IDE; |
159 virtual base::TimeDelta lowFrequencyAnimationInterval() const; | 161 virtual base::TimeDelta lowFrequencyAnimationInterval() const OVERRIDE; |
160 | 162 |
161 private: | 163 private: |
162 MockLayerTreeHostImpl(TestHooks*, const cc::CCLayerTreeSettings&, cc::CCLaye
rTreeHostImplClient*); | 164 MockLayerTreeHostImpl(TestHooks*, const cc::CCLayerTreeSettings&, cc::CCLaye
rTreeHostImplClient*); |
163 | 165 |
164 TestHooks* m_testHooks; | 166 TestHooks* m_testHooks; |
165 }; | 167 }; |
166 | 168 |
167 class CompositorFakeWebGraphicsContext3DWithTextureTracking : public WebKit::Com
positorFakeWebGraphicsContext3D { | 169 class CompositorFakeWebGraphicsContext3DWithTextureTracking : public WebKit::Com
positorFakeWebGraphicsContext3D { |
168 public: | 170 public: |
169 static PassOwnPtr<CompositorFakeWebGraphicsContext3DWithTextureTracking> cre
ate(Attributes); | 171 static PassOwnPtr<CompositorFakeWebGraphicsContext3DWithTextureTracking> cre
ate(Attributes); |
| 172 virtual ~CompositorFakeWebGraphicsContext3DWithTextureTracking(); |
170 | 173 |
171 virtual WebKit::WebGLId createTexture(); | 174 virtual WebKit::WebGLId createTexture(); |
172 | 175 |
173 virtual void deleteTexture(WebKit::WebGLId texture); | 176 virtual void deleteTexture(WebKit::WebGLId texture); |
174 | 177 |
175 virtual void bindTexture(WebKit::WGC3Denum target, WebKit::WebGLId texture); | 178 virtual void bindTexture(WebKit::WGC3Denum target, WebKit::WebGLId texture); |
176 | 179 |
177 int numTextures() const; | 180 int numTextures() const; |
178 int texture(int texture) const; | 181 int texture(int texture) const; |
179 void resetTextures(); | 182 void resetTextures(); |
(...skipping 15 matching lines...) Expand all Loading... |
195 TEST_F(TEST_FIXTURE_NAME, runSingleThread) \ | 198 TEST_F(TEST_FIXTURE_NAME, runSingleThread) \ |
196 { \ | 199 { \ |
197 runTest(false); \ | 200 runTest(false); \ |
198 } \ | 201 } \ |
199 TEST_F(TEST_FIXTURE_NAME, runMultiThread) \ | 202 TEST_F(TEST_FIXTURE_NAME, runMultiThread) \ |
200 { \ | 203 { \ |
201 runTest(true); \ | 204 runTest(true); \ |
202 } | 205 } |
203 | 206 |
204 #endif // CCThreadedTest_h | 207 #endif // CCThreadedTest_h |
OLD | NEW |