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

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: Fix tests 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_web_graphics_context_3d.h" 8 #include "cc/debug/test_web_graphics_context_3d.h"
9 #include "cc/output/managed_memory_policy.h" 9 #include "cc/output/managed_memory_policy.h"
10 #include "cc/output/output_surface_client.h" 10 #include "cc/output/output_surface_client.h"
11 #include "cc/output/software_output_device.h" 11 #include "cc/output/software_output_device.h"
12 #include "cc/test/fake_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_output_surface_client.h" 13 #include "cc/test/fake_output_surface_client.h"
14 #include "cc/test/scheduler_test_common.h" 14 #include "cc/test/scheduler_test_common.h"
15 #include "gpu/GLES2/gl2extchromium.h" 15 #include "gpu/GLES2/gl2extchromium.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h" 17 #include "third_party/WebKit/public/platform/WebGraphicsMemoryAllocation.h"
18 18
19 using WebKit::WebGraphicsMemoryAllocation; 19 using WebKit::WebGraphicsMemoryAllocation;
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 class TestOutputSurface : public OutputSurface { 24 class TestOutputSurface : public OutputSurface {
25 public: 25 public:
26 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 26 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
27 : OutputSurface(context3d.Pass()) {} 27 : OutputSurface(context3d.Pass()),
28 retroactive_begin_frame_deadline_enabled_(false),
29 override_retroactive_period_(false) {}
28 30
29 explicit TestOutputSurface( 31 explicit TestOutputSurface(
30 scoped_ptr<cc::SoftwareOutputDevice> software_device) 32 scoped_ptr<cc::SoftwareOutputDevice> software_device)
31 : OutputSurface(software_device.Pass()) {} 33 : OutputSurface(software_device.Pass()),
34 retroactive_begin_frame_deadline_enabled_(false),
35 override_retroactive_period_(false) {}
32 36
33 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 37 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
34 scoped_ptr<cc::SoftwareOutputDevice> software_device) 38 scoped_ptr<cc::SoftwareOutputDevice> software_device)
35 : OutputSurface(context3d.Pass(), software_device.Pass()) {} 39 : OutputSurface(context3d.Pass(), software_device.Pass()),
40 retroactive_begin_frame_deadline_enabled_(false),
41 override_retroactive_period_(false) {}
36 42
37 bool InitializeNewContext3D( 43 bool InitializeNewContext3D(
38 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { 44 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) {
39 return InitializeAndSetContext3D(new_context3d.Pass(), 45 return InitializeAndSetContext3D(new_context3d.Pass(),
40 scoped_refptr<ContextProvider>()); 46 scoped_refptr<ContextProvider>());
41 } 47 }
42 48
43 using OutputSurface::ReleaseGL; 49 using OutputSurface::ReleaseGL;
44 50
45 bool HasClientForTesting() { 51 bool HasClientForTesting() {
(...skipping 14 matching lines...) Expand all
60 } 66 }
61 67
62 int pending_swap_buffers() { 68 int pending_swap_buffers() {
63 return pending_swap_buffers_; 69 return pending_swap_buffers_;
64 } 70 }
65 71
66 void OnSwapBuffersCompleteForTesting() { 72 void OnSwapBuffersCompleteForTesting() {
67 OnSwapBuffersComplete(NULL); 73 OnSwapBuffersComplete(NULL);
68 } 74 }
69 75
70 void SetAlternateRetroactiveBeginFramePeriod(base::TimeDelta period) { 76 void EnableRetroactiveBeginFrameDeadline(bool enable,
71 alternate_retroactive_begin_frame_period_ = period; 77 bool override_retroactive_period,
78 base::TimeDelta period_override) {
79 retroactive_begin_frame_deadline_enabled_ = enable;
80 override_retroactive_period_ = override_retroactive_period;
81 retroactive_period_override_ = period_override;
72 } 82 }
73 83
74 protected: 84 protected:
75 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { 85 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE {
76 // For testing purposes, we check immediately rather than posting a task. 86 // For testing purposes, we check immediately rather than posting a task.
77 CheckForRetroactiveBeginFrame(); 87 CheckForRetroactiveBeginFrame();
78 } 88 }
79 89
80 virtual base::TimeDelta AlternateRetroactiveBeginFramePeriod() OVERRIDE { 90 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE {
81 return alternate_retroactive_begin_frame_period_; 91 if (retroactive_begin_frame_deadline_enabled_) {
92 if (override_retroactive_period_) {
93 return skipped_begin_frame_args_.frame_time +
94 retroactive_period_override_;
95 } else {
96 return OutputSurface::RetroactiveBeginFrameDeadline();
97 }
98 }
99 return base::TimeTicks();
82 } 100 }
83 101
84 base::TimeDelta alternate_retroactive_begin_frame_period_; 102 bool retroactive_begin_frame_deadline_enabled_;
103 bool override_retroactive_period_;
104 base::TimeDelta retroactive_period_override_;
85 }; 105 };
86 106
87 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { 107 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
88 scoped_ptr<TestWebGraphicsContext3D> context3d = 108 scoped_ptr<TestWebGraphicsContext3D> context3d =
89 TestWebGraphicsContext3D::Create(); 109 TestWebGraphicsContext3D::Create();
90 110
91 TestOutputSurface output_surface( 111 TestOutputSurface output_surface(
92 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 112 context3d.PassAs<WebKit::WebGraphicsContext3D>());
93 EXPECT_FALSE(output_surface.HasClientForTesting()); 113 EXPECT_FALSE(output_surface.HasClientForTesting());
94 114
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool throttle_frame_production = true; 215 bool throttle_frame_production = true;
196 const base::TimeDelta display_refresh_interval = 216 const base::TimeDelta display_refresh_interval =
197 BeginFrameArgs::DefaultInterval(); 217 BeginFrameArgs::DefaultInterval();
198 218
199 output_surface.InitializeBeginFrameEmulation( 219 output_surface.InitializeBeginFrameEmulation(
200 task_runner.get(), 220 task_runner.get(),
201 throttle_frame_production, 221 throttle_frame_production,
202 display_refresh_interval); 222 display_refresh_interval);
203 223
204 output_surface.SetMaxFramesPending(2); 224 output_surface.SetMaxFramesPending(2);
205 output_surface.SetAlternateRetroactiveBeginFramePeriod( 225 output_surface.EnableRetroactiveBeginFrameDeadline(
206 base::TimeDelta::FromSeconds(-1)); 226 false, false, base::TimeDelta());
207 227
208 // We should start off with 0 BeginFrames 228 // We should start off with 0 BeginFrames
209 EXPECT_EQ(client.begin_frame_count(), 0); 229 EXPECT_EQ(client.begin_frame_count(), 0);
210 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); 230 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
211 231
212 // We should not have a pending task until a BeginFrame has been requested. 232 // We should not have a pending task until a BeginFrame has been requested.
213 EXPECT_FALSE(task_runner->HasPendingTask()); 233 EXPECT_FALSE(task_runner->HasPendingTask());
214 output_surface.SetNeedsBeginFrame(true); 234 output_surface.SetNeedsBeginFrame(true);
215 EXPECT_TRUE(task_runner->HasPendingTask()); 235 EXPECT_TRUE(task_runner->HasPendingTask());
216 236
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 TestOutputSurface output_surface( 290 TestOutputSurface output_surface(
271 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 291 context3d.PassAs<WebKit::WebGraphicsContext3D>());
272 EXPECT_FALSE(output_surface.HasClientForTesting()); 292 EXPECT_FALSE(output_surface.HasClientForTesting());
273 293
274 FakeOutputSurfaceClient client; 294 FakeOutputSurfaceClient client;
275 EXPECT_TRUE(output_surface.BindToClient(&client)); 295 EXPECT_TRUE(output_surface.BindToClient(&client));
276 EXPECT_TRUE(output_surface.HasClientForTesting()); 296 EXPECT_TRUE(output_surface.HasClientForTesting());
277 EXPECT_FALSE(client.deferred_initialize_called()); 297 EXPECT_FALSE(client.deferred_initialize_called());
278 298
279 output_surface.SetMaxFramesPending(2); 299 output_surface.SetMaxFramesPending(2);
280 300 output_surface.EnableRetroactiveBeginFrameDeadline(
281 // Enable retroactive BeginFrames. 301 true, false, base::TimeDelta());
282 output_surface.SetAlternateRetroactiveBeginFramePeriod(
283 base::TimeDelta::FromSeconds(100000));
284 302
285 // Optimistically injected BeginFrames should be throttled if 303 // Optimistically injected BeginFrames should be throttled if
286 // SetNeedsBeginFrame is false... 304 // SetNeedsBeginFrame is false...
287 output_surface.SetNeedsBeginFrame(false); 305 output_surface.SetNeedsBeginFrame(false);
288 output_surface.BeginFrameForTesting(); 306 output_surface.BeginFrameForTesting();
289 EXPECT_EQ(client.begin_frame_count(), 0); 307 EXPECT_EQ(client.begin_frame_count(), 0);
290 // ...and retroactively triggered by a SetNeedsBeginFrame. 308 // ...and retroactively triggered by a SetNeedsBeginFrame.
291 output_surface.SetNeedsBeginFrame(true); 309 output_surface.SetNeedsBeginFrame(true);
292 EXPECT_EQ(client.begin_frame_count(), 1); 310 EXPECT_EQ(client.begin_frame_count(), 1);
293 311
(...skipping 29 matching lines...) Expand all
323 341
324 TestOutputSurface output_surface( 342 TestOutputSurface output_surface(
325 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 343 context3d.PassAs<WebKit::WebGraphicsContext3D>());
326 EXPECT_FALSE(output_surface.HasClientForTesting()); 344 EXPECT_FALSE(output_surface.HasClientForTesting());
327 345
328 FakeOutputSurfaceClient client; 346 FakeOutputSurfaceClient client;
329 EXPECT_TRUE(output_surface.BindToClient(&client)); 347 EXPECT_TRUE(output_surface.BindToClient(&client));
330 EXPECT_TRUE(output_surface.HasClientForTesting()); 348 EXPECT_TRUE(output_surface.HasClientForTesting());
331 EXPECT_FALSE(client.deferred_initialize_called()); 349 EXPECT_FALSE(client.deferred_initialize_called());
332 350
333 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(1000); 351 base::TimeDelta big_interval = base::TimeDelta::FromSeconds(10);
334 352
335 // Initialize BeginFrame emulation 353 // Initialize BeginFrame emulation
336 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 354 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
337 new base::TestSimpleTaskRunner; 355 new base::TestSimpleTaskRunner;
338 bool throttle_frame_production = true; 356 bool throttle_frame_production = true;
339 const base::TimeDelta display_refresh_interval = big_interval; 357 const base::TimeDelta display_refresh_interval = big_interval;
340 358
341 output_surface.InitializeBeginFrameEmulation( 359 output_surface.InitializeBeginFrameEmulation(
342 task_runner.get(), 360 task_runner.get(),
343 throttle_frame_production, 361 throttle_frame_production,
344 display_refresh_interval); 362 display_refresh_interval);
345 363
346 // We need to subtract an epsilon from Now() because some platforms have 364 // We need to subtract an epsilon from Now() because some platforms have
347 // a slow clock. 365 // a slow clock.
348 output_surface.OnVSyncParametersChangedForTesting( 366 output_surface.OnVSyncParametersChangedForTesting(
349 base::TimeTicks::Now() - base::TimeDelta::FromMilliseconds(1), 367 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1), big_interval);
350 display_refresh_interval);
351 368
352 output_surface.SetMaxFramesPending(2); 369 output_surface.SetMaxFramesPending(2);
353 output_surface.SetAlternateRetroactiveBeginFramePeriod( 370 output_surface.EnableRetroactiveBeginFrameDeadline(true, true, big_interval);
354 base::TimeDelta::FromSeconds(-1));
355 371
356 // We should start off with 0 BeginFrames 372 // We should start off with 0 BeginFrames
357 EXPECT_EQ(client.begin_frame_count(), 0); 373 EXPECT_EQ(client.begin_frame_count(), 0);
358 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); 374 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
359 375
360 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame. 376 // The first SetNeedsBeginFrame(true) should start a retroactive BeginFrame.
377 EXPECT_FALSE(task_runner->HasPendingTask());
361 output_surface.SetNeedsBeginFrame(true); 378 output_surface.SetNeedsBeginFrame(true);
362 EXPECT_TRUE(task_runner->HasPendingTask()); 379 EXPECT_TRUE(task_runner->HasPendingTask());
363 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2); 380 EXPECT_GT(task_runner->NextPendingTaskDelay(), big_interval / 2);
364 EXPECT_EQ(client.begin_frame_count(), 1); 381 EXPECT_EQ(client.begin_frame_count(), 1);
365 382
366 output_surface.SetNeedsBeginFrame(false); 383 output_surface.SetNeedsBeginFrame(false);
367 EXPECT_TRUE(task_runner->HasPendingTask()); 384 EXPECT_TRUE(task_runner->HasPendingTask());
368 EXPECT_EQ(client.begin_frame_count(), 1); 385 EXPECT_EQ(client.begin_frame_count(), 1);
369 386
370 // The second SetNeedBeginFrame(true) should not retroactively start a 387 // The second SetNeedBeginFrame(true) should not retroactively start a
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 client.memory_policy().priority_cutoff_when_not_visible); 436 client.memory_policy().priority_cutoff_when_not_visible);
420 437
421 // 0 bytes limit should be ignored. 438 // 0 bytes limit should be ignored.
422 allocation.bytesLimitWhenVisible = 0; 439 allocation.bytesLimitWhenVisible = 0;
423 context->SetMemoryAllocation(allocation); 440 context->SetMemoryAllocation(allocation);
424 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible); 441 EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
425 } 442 }
426 443
427 } // namespace 444 } // namespace
428 } // namespace cc 445 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698