Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: cc/output/output_surface_unittest.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: Add an --enable-deadline-scheduler commandline flag. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) { 272 TEST(OutputSurfaceTest, OptimisticAndRetroactiveBeginFrames) {
253 TestOutputSurface output_surface(TestContextProvider::Create()); 273 TestOutputSurface output_surface(TestContextProvider::Create());
254 EXPECT_FALSE(output_surface.HasClient()); 274 EXPECT_FALSE(output_surface.HasClient());
255 275
256 FakeOutputSurfaceClient client; 276 FakeOutputSurfaceClient client;
257 EXPECT_TRUE(output_surface.BindToClient(&client)); 277 EXPECT_TRUE(output_surface.BindToClient(&client));
258 EXPECT_TRUE(output_surface.HasClient()); 278 EXPECT_TRUE(output_surface.HasClient());
259 EXPECT_FALSE(client.deferred_initialize_called()); 279 EXPECT_FALSE(client.deferred_initialize_called());
260 280
261 output_surface.SetMaxFramesPending(2); 281 output_surface.SetMaxFramesPending(2);
262 282 output_surface.EnableRetroactiveBeginFrameDeadline(
263 // Enable retroactive BeginFrames. 283 true, false, base::TimeDelta());
264 output_surface.SetAlternateRetroactiveBeginFramePeriod(
265 base::TimeDelta::FromSeconds(100000));
266 284
267 // Optimistically injected BeginFrames should be throttled if 285 // Optimistically injected BeginFrames should be throttled if
268 // SetNeedsBeginFrame is false... 286 // SetNeedsBeginFrame is false...
269 output_surface.SetNeedsBeginFrame(false); 287 output_surface.SetNeedsBeginFrame(false);
270 output_surface.BeginFrameForTesting(); 288 output_surface.BeginFrameForTesting();
271 EXPECT_EQ(client.begin_frame_count(), 0); 289 EXPECT_EQ(client.begin_frame_count(), 0);
272 // ...and retroactively triggered by a SetNeedsBeginFrame. 290 // ...and retroactively triggered by a SetNeedsBeginFrame.
273 output_surface.SetNeedsBeginFrame(true); 291 output_surface.SetNeedsBeginFrame(true);
274 EXPECT_EQ(client.begin_frame_count(), 1); 292 EXPECT_EQ(client.begin_frame_count(), 1);
275 293
(...skipping 28 matching lines...) Expand all
304 TestContextProvider::Create(); 322 TestContextProvider::Create();
305 323
306 TestOutputSurface output_surface(context_provider); 324 TestOutputSurface output_surface(context_provider);
307 EXPECT_FALSE(output_surface.HasClient()); 325 EXPECT_FALSE(output_surface.HasClient());
308 326
309 FakeOutputSurfaceClient client; 327 FakeOutputSurfaceClient client;
310 EXPECT_TRUE(output_surface.BindToClient(&client)); 328 EXPECT_TRUE(output_surface.BindToClient(&client));
311 EXPECT_TRUE(output_surface.HasClient()); 329 EXPECT_TRUE(output_surface.HasClient());
312 EXPECT_FALSE(client.deferred_initialize_called()); 330 EXPECT_FALSE(client.deferred_initialize_called());
313 331
314 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); 332 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10);
315 333
316 // Initialize BeginFrame emulation 334 // Initialize BeginFrame emulation
317 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 335 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
318 new base::TestSimpleTaskRunner; 336 new base::TestSimpleTaskRunner;
319 bool throttle_frame_production = true; 337 bool throttle_frame_production = true;
320 const base::TimeDelta display_refresh_interval = big_interval; 338 const base::TimeDelta display_refresh_interval = big_interval;
321 339
322 output_surface.InitializeBeginFrameEmulation( 340 output_surface.InitializeBeginFrameEmulation(
323 task_runner.get(), 341 task_runner.get(),
324 throttle_frame_production, 342 throttle_frame_production,
325 display_refresh_interval); 343 display_refresh_interval);
326 344
327 // We need to subtract an epsilon from Now() because some platforms have 345 // We need to subtract an epsilon from Now() because some platforms have
328 // a slow clock. 346 // a slow clock.
329 output_surface.OnVSyncParametersChangedForTesting( 347 output_surface.OnVSyncParametersChangedForTesting(
330 base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(1), 348 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1), big_interval);
331 display_refresh_interval);
332 349
333 output_surface.SetMaxFramesPending(2); 350 output_surface.SetMaxFramesPending(2);
334 output_surface.SetAlternateRetroactiveBeginFramePeriod( 351 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval);
335 base::TimeDelta::FromSeconds(-1));
336 352
337 // We should start off with 0 BeginFrames 353 // We should start off with 0 BeginFrames
338 EXPECT_EQ(client.begin_frame_count(), 0); 354 EXPECT_EQ(client.begin_frame_count(), 0);
339 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); 355 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
340 356
341 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. 357 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame.
358 EXPECT_FALSE(task_runner->HasPendingTask());
342 output_surface.SetNeedsBeginFrame(true); 359 output_surface.SetNeedsBeginFrame(true);
343 EXPECT_TRUE(task_runner->HasPendingTask()); 360 EXPECT_TRUE(task_runner->HasPendingTask());
344 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); 361 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2);
345 EXPECT_EQ(client.begin_frame_count(), 1); 362 EXPECT_EQ(client.begin_frame_count(), 1);
346 363
347 output_surface.SetNeedsBeginFrame(false); 364 output_surface.SetNeedsBeginFrame(false);
348 EXPECT_TRUE(task_runner->HasPendingTask()); 365 EXPECT_TRUE(task_runner->HasPendingTask());
349 EXPECT_EQ(client.begin_frame_count(), 1); 366 EXPECT_EQ(client.begin_frame_count(), 1);
350 367
351 // The second SetNeedBeginFrame(true) should not retroactively start a 368 // The second SetNeedBeginFrame(true) should not retroactively start a
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 419
403 // 0 bytes limit should be ignored. 420 // 0 bytes limit should be ignored.
404 policy.bytes_limit_when_visible = 0; 421 policy.bytes_limit_when_visible = 0;
405 context_provider->SetMemoryAllocation(policy, 422 context_provider->SetMemoryAllocation(policy,
406 discard_backbuffer_when_not_visible); 423 discard_backbuffer_when_not_visible);
407 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); 424 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
408 } 425 }
409 426
410 } // namespace 427 } // namespace
411 } // namespace cc 428 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698