| 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 "cc/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
| 6 | 6 |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "cc/debug/test_context_provider.h" | 8 #include "cc/debug/test_context_provider.h" |
| 9 #include "cc/debug/test_web_graphics_context_3d.h" | 9 #include "cc/debug/test_web_graphics_context_3d.h" |
| 10 #include "cc/output/managed_memory_policy.h" | 10 #include "cc/output/managed_memory_policy.h" |
| 11 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
| 12 #include "cc/output/software_output_device.h" | 12 #include "cc/output/software_output_device.h" |
| 13 #include "cc/test/fake_output_surface.h" | 13 #include "cc/test/fake_output_surface.h" |
| 14 #include "cc/test/fake_output_surface_client.h" | 14 #include "cc/test/fake_output_surface_client.h" |
| 15 #include "cc/test/scheduler_test_common.h" | 15 #include "cc/test/scheduler_test_common.h" |
| 16 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class TestOutputSurface : public OutputSurface { | 22 class TestOutputSurface : public OutputSurface { |
| 23 public: | 23 public: |
| 24 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) | 24 explicit TestOutputSurface(scoped_refptr<ContextProvider> context_provider) |
| 25 : OutputSurface(context_provider) {} | 25 : OutputSurface(context_provider), |
| 26 retroactive_begin_frame_deadline_enabled_(false), |
| 27 override_retroactive_period_(false) {} |
| 26 | 28 |
| 27 explicit TestOutputSurface( | 29 explicit TestOutputSurface( |
| 28 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 30 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
| 29 : OutputSurface(software_device.Pass()) {} | 31 : OutputSurface(software_device.Pass()), |
| 32 retroactive_begin_frame_deadline_enabled_(false), |
| 33 override_retroactive_period_(false) {} |
| 30 | 34 |
| 31 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, | 35 TestOutputSurface(scoped_refptr<ContextProvider> context_provider, |
| 32 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 36 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
| 33 : OutputSurface(context_provider, software_device.Pass()) {} | 37 : OutputSurface(context_provider, software_device.Pass()), |
| 38 retroactive_begin_frame_deadline_enabled_(false), |
| 39 override_retroactive_period_(false) {} |
| 34 | 40 |
| 35 bool InitializeNewContext3d( | 41 bool InitializeNewContext3d( |
| 36 scoped_refptr<ContextProvider> new_context_provider) { | 42 scoped_refptr<ContextProvider> new_context_provider) { |
| 37 return InitializeAndSetContext3d(new_context_provider, | 43 return InitializeAndSetContext3d(new_context_provider, |
| 38 scoped_refptr<ContextProvider>()); | 44 scoped_refptr<ContextProvider>()); |
| 39 } | 45 } |
| 40 | 46 |
| 41 using OutputSurface::ReleaseGL; | 47 using OutputSurface::ReleaseGL; |
| 42 | 48 |
| 43 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, | 49 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 } | 60 } |
| 55 | 61 |
| 56 int pending_swap_buffers() { | 62 int pending_swap_buffers() { |
| 57 return pending_swap_buffers_; | 63 return pending_swap_buffers_; |
| 58 } | 64 } |
| 59 | 65 |
| 60 void OnSwapBuffersCompleteForTesting() { | 66 void OnSwapBuffersCompleteForTesting() { |
| 61 OnSwapBuffersComplete(NULL); | 67 OnSwapBuffersComplete(NULL); |
| 62 } | 68 } |
| 63 | 69 |
| 64 void SetAlternateRetroactiveBeginFramePeriod(base::TimeDelta period) { | 70 void EnableRetroactiveBeginFrameDeadline(bool enable, |
| 65 alternate_retroactive_begin_frame_period_ = period; | 71 bool override_retroactive_period, |
| 72 base::TimeDelta period_override) { |
| 73 retroactive_begin_frame_deadline_enabled_ = enable; |
| 74 override_retroactive_period_ = override_retroactive_period; |
| 75 retroactive_period_override_ = period_override; |
| 66 } | 76 } |
| 67 | 77 |
| 68 protected: | 78 protected: |
| 69 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { | 79 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { |
| 70 // For testing purposes, we check immediately rather than posting a task. | 80 // For testing purposes, we check immediately rather than posting a task. |
| 71 CheckForRetroactiveBeginFrame(); | 81 CheckForRetroactiveBeginFrame(); |
| 72 } | 82 } |
| 73 | 83 |
| 74 virtual base::TimeDelta AlternateRetroactiveBeginFramePeriod() OVERRIDE { | 84 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE { |
| 75 return alternate_retroactive_begin_frame_period_; | 85 if (retroactive_begin_frame_deadline_enabled_) { |
| 86 if (override_retroactive_period_) { |
| 87 return skipped_begin_frame_args_.frame_time + |
| 88 retroactive_period_override_; |
| 89 } else { |
| 90 return OutputSurface::RetroactiveBeginFrameDeadline(); |
| 91 } |
| 92 } |
| 93 return base::TimeTicks(); |
| 76 } | 94 } |
| 77 | 95 |
| 78 base::TimeDelta alternate_retroactive_begin_frame_period_; | 96 bool retroactive_begin_frame_deadline_enabled_; |
| 97 bool override_retroactive_period_; |
| 98 base::TimeDelta retroactive_period_override_; |
| 79 }; | 99 }; |
| 80 | 100 |
| 81 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { | 101 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { |
| 82 TestOutputSurface output_surface(TestContextProvider::Create()); | 102 TestOutputSurface output_surface(TestContextProvider::Create()); |
| 83 EXPECT_FALSE(output_surface.HasClient()); | 103 EXPECT_FALSE(output_surface.HasClient()); |
| 84 | 104 |
| 85 FakeOutputSurfaceClient client; | 105 FakeOutputSurfaceClient client; |
| 86 EXPECT_TRUE(output_surface.BindToClient(&client)); | 106 EXPECT_TRUE(output_surface.BindToClient(&client)); |
| 87 EXPECT_TRUE(output_surface.HasClient()); | 107 EXPECT_TRUE(output_surface.HasClient()); |
| 88 EXPECT_FALSE(client.deferred_initialize_called()); | 108 EXPECT_FALSE(client.deferred_initialize_called()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 bool throttle_frame_production = true; | 201 bool throttle_frame_production = true; |
| 182 const base::TimeDelta display_refresh_interval = | 202 const base::TimeDelta display_refresh_interval = |
| 183 BeginFrameArgs::DefaultInterval(); | 203 BeginFrameArgs::DefaultInterval(); |
| 184 | 204 |
| 185 output_surface.InitializeBeginFrameEmulation( | 205 output_surface.InitializeBeginFrameEmulation( |
| 186 task_runner.get(), | 206 task_runner.get(), |
| 187 throttle_frame_production, | 207 throttle_frame_production, |
| 188 display_refresh_interval); | 208 display_refresh_interval); |
| 189 | 209 |
| 190 output_surface.SetMaxFramesPending(2); | 210 output_surface.SetMaxFramesPending(2); |
| 191 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 211 output_surface.EnableRetroactiveBeginFrameDeadline( |
| 192 base::TimeDelta::FromSeconds(-1)); | 212 false, false, base::TimeDelta()); |
| 193 | 213 |
| 194 // We should start off with 0 BeginFrames | 214 // We should start off with 0 BeginFrames |
| 195 EXPECT_EQ(client.begin_frame_count(), 0); | 215 EXPECT_EQ(client.begin_frame_count(), 0); |
| 196 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 216 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
| 197 | 217 |
| 198 // We should not have a pending task until a BeginFrame has been requested. | 218 // We should not have a pending task until a BeginFrame has been requested. |
| 199 EXPECT_FALSE(task_runner->HasPendingTask()); | 219 EXPECT_FALSE(task_runner->HasPendingTask()); |
| 200 output_surface.SetNeedsBeginFrame(true); | 220 output_surface.SetNeedsBeginFrame(true); |
| 201 EXPECT_TRUE(task_runner->HasPendingTask()); | 221 EXPECT_TRUE(task_runner->HasPendingTask()); |
| 202 | 222 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { | 275 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { |
| 256 TestOutputSurface output_surface(TestContextProvider::Create()); | 276 TestOutputSurface output_surface(TestContextProvider::Create()); |
| 257 EXPECT_FALSE(output_surface.HasClient()); | 277 EXPECT_FALSE(output_surface.HasClient()); |
| 258 | 278 |
| 259 FakeOutputSurfaceClient client; | 279 FakeOutputSurfaceClient client; |
| 260 EXPECT_TRUE(output_surface.BindToClient(&client)); | 280 EXPECT_TRUE(output_surface.BindToClient(&client)); |
| 261 EXPECT_TRUE(output_surface.HasClient()); | 281 EXPECT_TRUE(output_surface.HasClient()); |
| 262 EXPECT_FALSE(client.deferred_initialize_called()); | 282 EXPECT_FALSE(client.deferred_initialize_called()); |
| 263 | 283 |
| 264 output_surface.SetMaxFramesPending(2); | 284 output_surface.SetMaxFramesPending(2); |
| 265 | 285 output_surface.EnableRetroactiveBeginFrameDeadline( |
| 266 // Enable retroactive BeginFrames. | 286 true, false, base::TimeDelta()); |
| 267 output_surface.SetAlternateRetroactiveBeginFramePeriod( | |
| 268 base::TimeDelta::FromSeconds(100000)); | |
| 269 | 287 |
| 270 // Optimistically injected BeginFrames should be throttled if | 288 // Optimistically injected BeginFrames should be throttled if |
| 271 // SetNeedsBeginFrame is false... | 289 // SetNeedsBeginFrame is false... |
| 272 output_surface.SetNeedsBeginFrame(false); | 290 output_surface.SetNeedsBeginFrame(false); |
| 273 output_surface.BeginFrameForTesting(); | 291 output_surface.BeginFrameForTesting(); |
| 274 EXPECT_EQ(client.begin_frame_count(), 0); | 292 EXPECT_EQ(client.begin_frame_count(), 0); |
| 275 // ...and retroactively triggered by a SetNeedsBeginFrame. | 293 // ...and retroactively triggered by a SetNeedsBeginFrame. |
| 276 output_surface.SetNeedsBeginFrame(true); | 294 output_surface.SetNeedsBeginFrame(true); |
| 277 EXPECT_EQ(client.begin_frame_count(), 1); | 295 EXPECT_EQ(client.begin_frame_count(), 1); |
| 278 | 296 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 309 TestContextProvider::Create(); | 327 TestContextProvider::Create(); |
| 310 | 328 |
| 311 TestOutputSurface output_surface(context_provider); | 329 TestOutputSurface output_surface(context_provider); |
| 312 EXPECT_FALSE(output_surface.HasClient()); | 330 EXPECT_FALSE(output_surface.HasClient()); |
| 313 | 331 |
| 314 FakeOutputSurfaceClient client; | 332 FakeOutputSurfaceClient client; |
| 315 EXPECT_TRUE(output_surface.BindToClient(&client)); | 333 EXPECT_TRUE(output_surface.BindToClient(&client)); |
| 316 EXPECT_TRUE(output_surface.HasClient()); | 334 EXPECT_TRUE(output_surface.HasClient()); |
| 317 EXPECT_FALSE(client.deferred_initialize_called()); | 335 EXPECT_FALSE(client.deferred_initialize_called()); |
| 318 | 336 |
| 319 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); | 337 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10); |
| 320 | 338 |
| 321 // Initialize BeginFrame emulation | 339 // Initialize BeginFrame emulation |
| 322 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | 340 scoped_refptr<base::TestSimpleTaskRunner> task_runner = |
| 323 new base::TestSimpleTaskRunner; | 341 new base::TestSimpleTaskRunner; |
| 324 bool throttle_frame_production = true; | 342 bool throttle_frame_production = true; |
| 325 const base::TimeDelta display_refresh_interval = big_interval; | 343 const base::TimeDelta display_refresh_interval = big_interval; |
| 326 | 344 |
| 327 output_surface.InitializeBeginFrameEmulation( | 345 output_surface.InitializeBeginFrameEmulation( |
| 328 task_runner.get(), | 346 task_runner.get(), |
| 329 throttle_frame_production, | 347 throttle_frame_production, |
| 330 display_refresh_interval); | 348 display_refresh_interval); |
| 331 | 349 |
| 332 // We need to subtract an epsilon from Now() because some platforms have | 350 // We need to subtract an epsilon from Now() because some platforms have |
| 333 // a slow clock. | 351 // a slow clock. |
| 334 output_surface.OnVSyncParametersChangedForTesting( | 352 output_surface.OnVSyncParametersChangedForTesting( |
| 335 base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(1), | 353 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1), big_interval); |
| 336 display_refresh_interval); | |
| 337 | 354 |
| 338 output_surface.SetMaxFramesPending(2); | 355 output_surface.SetMaxFramesPending(2); |
| 339 output_surface.SetAlternateRetroactiveBeginFramePeriod( | 356 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval); |
| 340 base::TimeDelta::FromSeconds(-1)); | |
| 341 | 357 |
| 342 // We should start off with 0 BeginFrames | 358 // We should start off with 0 BeginFrames |
| 343 EXPECT_EQ(client.begin_frame_count(), 0); | 359 EXPECT_EQ(client.begin_frame_count(), 0); |
| 344 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); | 360 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); |
| 345 | 361 |
| 346 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. | 362 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. |
| 363 EXPECT_FALSE(task_runner->HasPendingTask()); |
| 347 output_surface.SetNeedsBeginFrame(true); | 364 output_surface.SetNeedsBeginFrame(true); |
| 348 EXPECT_TRUE(task_runner->HasPendingTask()); | 365 EXPECT_TRUE(task_runner->HasPendingTask()); |
| 349 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); | 366 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); |
| 350 EXPECT_EQ(client.begin_frame_count(), 1); | 367 EXPECT_EQ(client.begin_frame_count(), 1); |
| 351 | 368 |
| 352 output_surface.SetNeedsBeginFrame(false); | 369 output_surface.SetNeedsBeginFrame(false); |
| 353 EXPECT_TRUE(task_runner->HasPendingTask()); | 370 EXPECT_TRUE(task_runner->HasPendingTask()); |
| 354 EXPECT_EQ(client.begin_frame_count(), 1); | 371 EXPECT_EQ(client.begin_frame_count(), 1); |
| 355 | 372 |
| 356 // The second SetNeedBeginFrame(true) should not retroactively start a | 373 // The second SetNeedBeginFrame(true) should not retroactively start a |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 424 |
| 408 // 0 bytes limit should be ignored. | 425 // 0 bytes limit should be ignored. |
| 409 policy.bytes_limit_when_visible = 0; | 426 policy.bytes_limit_when_visible = 0; |
| 410 context_provider->SetMemoryAllocation(policy, | 427 context_provider->SetMemoryAllocation(policy, |
| 411 discard_backbuffer_when_not_visible); | 428 discard_backbuffer_when_not_visible); |
| 412 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); | 429 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); |
| 413 } | 430 } |
| 414 | 431 |
| 415 } // namespace | 432 } // namespace |
| 416 } // namespace cc | 433 } // namespace cc |
| OLD | NEW |