| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/test/test_simple_task_runner.h" |
| 5 #include "cc/output/output_surface.h" | 6 #include "cc/output/output_surface.h" |
| 6 #include "cc/output/output_surface_client.h" | 7 #include "cc/output/output_surface_client.h" |
| 7 #include "cc/output/software_output_device.h" | 8 #include "cc/output/software_output_device.h" |
| 8 #include "cc/test/scheduler_test_common.h" | 9 #include "cc/test/scheduler_test_common.h" |
| 9 #include "cc/test/test_web_graphics_context_3d.h" | 10 #include "cc/test/test_web_graphics_context_3d.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 11 #include "gpu/GLES2/gl2extchromium.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 namespace { | 15 namespace { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 TestOutputSurface output_surface( | 202 TestOutputSurface output_surface( |
| 202 context3d.PassAs<WebKit::WebGraphicsContext3D>()); | 203 context3d.PassAs<WebKit::WebGraphicsContext3D>()); |
| 203 EXPECT_FALSE(output_surface.HasClientForTesting()); | 204 EXPECT_FALSE(output_surface.HasClientForTesting()); |
| 204 | 205 |
| 205 FakeOutputSurfaceClient client; | 206 FakeOutputSurfaceClient client; |
| 206 EXPECT_TRUE(output_surface.BindToClient(&client)); | 207 EXPECT_TRUE(output_surface.BindToClient(&client)); |
| 207 EXPECT_TRUE(output_surface.HasClientForTesting()); | 208 EXPECT_TRUE(output_surface.HasClientForTesting()); |
| 208 EXPECT_FALSE(client.deferred_initialize_called()); | 209 EXPECT_FALSE(client.deferred_initialize_called()); |
| 209 | 210 |
| 210 // Initialize BeginFrame emulation | 211 // Initialize BeginFrame emulation |
| 211 FakeThread impl_thread; | 212 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
| 213 new base::TestSimpleTaskRunner; |
| 212 bool throttle_frame_production = true; | 214 bool throttle_frame_production = true; |
| 213 const base::TimeDelta display_refresh_interval = | 215 const base::TimeDelta display_refresh_interval = |
| 214 base::TimeDelta::FromMicroseconds(16666); | 216 base::TimeDelta::FromMicroseconds(16666); |
| 215 | 217 |
| 216 output_surface.InitializeBeginFrameEmulation( | 218 output_surface.InitializeBeginFrameEmulation( |
| 217 &impl_thread, | 219 task_runner.get(), |
| 218 throttle_frame_production, | 220 throttle_frame_production, |
| 219 display_refresh_interval); | 221 display_refresh_interval); |
| 220 | 222 |
| 221 output_surface.SetMaxFramesPending(2); | 223 output_surface.SetMaxFramesPending(2); |
| 222 | 224 |
| 223 // We should start off with 0 BeginFrames | 225 // We should start off with 0 BeginFrames |
| 224 EXPECT_EQ(client.begin_frame_count(), 0); | 226 EXPECT_EQ(client.begin_frame_count(), 0); |
| 225 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 227 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
| 226 | 228 |
| 227 // We should not have a pending task until a BeginFrame has been requested. | 229 // We should not have a pending task until a BeginFrame has been requested. |
| 228 EXPECT_FALSE(impl_thread.HasPendingTask()); | 230 EXPECT_FALSE(task_runner->HasPendingTask()); |
| 229 output_surface.SetNeedsBeginFrame(true); | 231 output_surface.SetNeedsBeginFrame(true); |
| 230 EXPECT_TRUE(impl_thread.HasPendingTask()); | 232 EXPECT_TRUE(task_runner->HasPendingTask()); |
| 231 | 233 |
| 232 // BeginFrame should be called on the first tick. | 234 // BeginFrame should be called on the first tick. |
| 233 impl_thread.RunPendingTask(); | 235 task_runner->RunPendingTasks(); |
| 234 EXPECT_EQ(client.begin_frame_count(), 1); | 236 EXPECT_EQ(client.begin_frame_count(), 1); |
| 235 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 237 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
| 236 | 238 |
| 237 // BeginFrame should not be called when there is a pending BeginFrame. | 239 // BeginFrame should not be called when there is a pending BeginFrame. |
| 238 impl_thread.RunPendingTask(); | 240 task_runner->RunPendingTasks(); |
| 239 EXPECT_EQ(client.begin_frame_count(), 1); | 241 EXPECT_EQ(client.begin_frame_count(), 1); |
| 240 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 242 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
| 241 | 243 |
| 242 // DidSwapBuffers should clear the pending BeginFrame. | 244 // DidSwapBuffers should clear the pending BeginFrame. |
| 243 output_surface.DidSwapBuffersForTesting(); | 245 output_surface.DidSwapBuffersForTesting(); |
| 244 EXPECT_EQ(client.begin_frame_count(), 1); | 246 EXPECT_EQ(client.begin_frame_count(), 1); |
| 245 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 247 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 246 impl_thread.RunPendingTask(); | 248 task_runner->RunPendingTasks(); |
| 247 EXPECT_EQ(client.begin_frame_count(), 2); | 249 EXPECT_EQ(client.begin_frame_count(), 2); |
| 248 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 250 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 249 | 251 |
| 250 // BeginFrame should be throttled by pending swap buffers. | 252 // BeginFrame should be throttled by pending swap buffers. |
| 251 output_surface.DidSwapBuffersForTesting(); | 253 output_surface.DidSwapBuffersForTesting(); |
| 252 EXPECT_EQ(client.begin_frame_count(), 2); | 254 EXPECT_EQ(client.begin_frame_count(), 2); |
| 253 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 255 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
| 254 impl_thread.RunPendingTask(); | 256 task_runner->RunPendingTasks(); |
| 255 EXPECT_EQ(client.begin_frame_count(), 2); | 257 EXPECT_EQ(client.begin_frame_count(), 2); |
| 256 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 258 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
| 257 | 259 |
| 258 // SwapAck should decrement pending swap buffers and unblock BeginFrame again. | 260 // SwapAck should decrement pending swap buffers and unblock BeginFrame again. |
| 259 output_surface.OnSwapBuffersCompleteForTesting(); | 261 output_surface.OnSwapBuffersCompleteForTesting(); |
| 260 EXPECT_EQ(client.begin_frame_count(), 2); | 262 EXPECT_EQ(client.begin_frame_count(), 2); |
| 261 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 263 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 262 impl_thread.RunPendingTask(); | 264 task_runner->RunPendingTasks(); |
| 263 EXPECT_EQ(client.begin_frame_count(), 3); | 265 EXPECT_EQ(client.begin_frame_count(), 3); |
| 264 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 266 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 265 | 267 |
| 266 // Calling SetNeedsBeginFrame again indicates a swap did not occur but | 268 // Calling SetNeedsBeginFrame again indicates a swap did not occur but |
| 267 // the client still wants another BeginFrame. | 269 // the client still wants another BeginFrame. |
| 268 output_surface.SetNeedsBeginFrame(true); | 270 output_surface.SetNeedsBeginFrame(true); |
| 269 impl_thread.RunPendingTask(); | 271 task_runner->RunPendingTasks(); |
| 270 EXPECT_EQ(client.begin_frame_count(), 4); | 272 EXPECT_EQ(client.begin_frame_count(), 4); |
| 271 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 273 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 272 | 274 |
| 273 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. | 275 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. |
| 274 output_surface.SetNeedsBeginFrame(false); | 276 output_surface.SetNeedsBeginFrame(false); |
| 275 impl_thread.RunPendingTask(); | 277 task_runner->RunPendingTasks(); |
| 276 EXPECT_FALSE(impl_thread.HasPendingTask()); | 278 EXPECT_FALSE(task_runner->HasPendingTask()); |
| 277 EXPECT_EQ(client.begin_frame_count(), 4); | 279 EXPECT_EQ(client.begin_frame_count(), 4); |
| 278 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 280 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 279 | 281 |
| 280 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should be | 282 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should be |
| 281 // allowed. | 283 // allowed. |
| 282 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); | 284 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); |
| 283 EXPECT_EQ(client.begin_frame_count(), 5); | 285 EXPECT_EQ(client.begin_frame_count(), 5); |
| 284 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 286 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 285 | 287 |
| 286 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should | 288 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should |
| 287 // still be throttled by pending begin frames however. | 289 // still be throttled by pending begin frames however. |
| 288 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); | 290 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); |
| 289 EXPECT_EQ(client.begin_frame_count(), 5); | 291 EXPECT_EQ(client.begin_frame_count(), 5); |
| 290 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); | 292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); |
| 291 | 293 |
| 292 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should | 294 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should |
| 293 // also be throttled by pending swap buffers. | 295 // also be throttled by pending swap buffers. |
| 294 output_surface.DidSwapBuffersForTesting(); | 296 output_surface.DidSwapBuffersForTesting(); |
| 295 EXPECT_EQ(client.begin_frame_count(), 5); | 297 EXPECT_EQ(client.begin_frame_count(), 5); |
| 296 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 298 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
| 297 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); | 299 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); |
| 298 EXPECT_EQ(client.begin_frame_count(), 5); | 300 EXPECT_EQ(client.begin_frame_count(), 5); |
| 299 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); | 301 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); |
| 300 } | 302 } |
| 301 | 303 |
| 302 } // namespace | 304 } // namespace |
| 303 } // namespace cc | 305 } // namespace cc |
| OLD | NEW |