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

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: else if typo Created 7 years, 5 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 "base/test/test_simple_task_runner.h" 5 #include "base/test/test_simple_task_runner.h"
6 #include "cc/output/managed_memory_policy.h" 6 #include "cc/output/managed_memory_policy.h"
7 #include "cc/output/output_surface.h" 7 #include "cc/output/output_surface.h"
8 #include "cc/output/output_surface_client.h" 8 #include "cc/output/output_surface_client.h"
9 #include "cc/output/software_output_device.h" 9 #include "cc/output/software_output_device.h"
10 #include "cc/test/scheduler_test_common.h" 10 #include "cc/test/scheduler_test_common.h"
11 #include "cc/test/test_web_graphics_context_3d.h" 11 #include "cc/test/test_web_graphics_context_3d.h"
12 #include "gpu/GLES2/gl2extchromium.h" 12 #include "gpu/GLES2/gl2extchromium.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using WebKit::WebGraphicsMemoryAllocation; 15 using WebKit::WebGraphicsMemoryAllocation;
16 16
17 namespace cc { 17 namespace cc {
18 namespace { 18 namespace {
19 19
20 class TestOutputSurface : public OutputSurface { 20 class TestOutputSurface : public OutputSurface {
21 public: 21 public:
22 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 22 explicit TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
23 : OutputSurface(context3d.Pass()) {} 23 : OutputSurface(context3d.Pass()),
24 retroactive_begin_frame_deadline_enabled_(false) {}
24 25
25 explicit TestOutputSurface( 26 explicit TestOutputSurface(
26 scoped_ptr<cc::SoftwareOutputDevice> software_device) 27 scoped_ptr<cc::SoftwareOutputDevice> software_device)
27 : OutputSurface(software_device.Pass()) {} 28 : OutputSurface(software_device.Pass()),
29 retroactive_begin_frame_deadline_enabled_(false) {}
28 30
29 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 31 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
30 scoped_ptr<cc::SoftwareOutputDevice> software_device) 32 scoped_ptr<cc::SoftwareOutputDevice> software_device)
31 : OutputSurface(context3d.Pass(), software_device.Pass()) {} 33 : OutputSurface(context3d.Pass(), software_device.Pass()),
34 retroactive_begin_frame_deadline_enabled_(false) {}
32 35
33 bool InitializeNewContext3D( 36 bool InitializeNewContext3D(
34 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { 37 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) {
35 return InitializeAndSetContext3D(new_context3d.Pass(), 38 return InitializeAndSetContext3D(new_context3d.Pass(),
36 scoped_refptr<ContextProvider>()); 39 scoped_refptr<ContextProvider>());
37 } 40 }
38 41
39 bool HasClientForTesting() { 42 bool HasClientForTesting() {
40 return HasClient(); 43 return HasClient();
41 } 44 }
(...skipping 12 matching lines...) Expand all
54 } 57 }
55 58
56 int pending_swap_buffers() { 59 int pending_swap_buffers() {
57 return pending_swap_buffers_; 60 return pending_swap_buffers_;
58 } 61 }
59 62
60 void OnSwapBuffersCompleteForTesting() { 63 void OnSwapBuffersCompleteForTesting() {
61 OnSwapBuffersComplete(NULL); 64 OnSwapBuffersComplete(NULL);
62 } 65 }
63 66
64 void SetRetroactiveBeginFramePeriod(base::TimeDelta period) { 67 void EnableRetroactiveBeginFrameDeadline(bool enable) {
65 retroactive_begin_frame_period_ = period; 68 retroactive_begin_frame_deadline_enabled_ = enable;
66 } 69 }
67 70
68 protected: 71 protected:
69 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { 72 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE {
70 // For testing purposes, we check immediately rather than posting a task. 73 // For testing purposes, we check immediately rather than posting a task.
71 CheckForRetroactiveBeginFrame(); 74 CheckForRetroactiveBeginFrame();
72 } 75 }
73 76
74 virtual base::TimeDelta RetroactiveBeginFramePeriod() OVERRIDE { 77 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE {
75 return retroactive_begin_frame_period_; 78 if (retroactive_begin_frame_deadline_enabled_)
79 return OutputSurface::RetroactiveBeginFrameDeadline();
80 return base::TimeTicks();
76 } 81 }
77 82
78 base::TimeDelta retroactive_begin_frame_period_; 83 bool retroactive_begin_frame_deadline_enabled_;
79 }; 84 };
80 85
81 class FakeOutputSurfaceClient : public OutputSurfaceClient { 86 class FakeOutputSurfaceClient : public OutputSurfaceClient {
82 public: 87 public:
83 FakeOutputSurfaceClient() 88 FakeOutputSurfaceClient()
84 : begin_frame_count_(0), 89 : begin_frame_count_(0),
85 deferred_initialize_result_(true), 90 deferred_initialize_result_(true),
86 deferred_initialize_called_(false), 91 deferred_initialize_called_(false),
87 did_lose_output_surface_called_(false), 92 did_lose_output_surface_called_(false),
88 memory_policy_(0), 93 memory_policy_(0),
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 bool throttle_frame_production = true; 254 bool throttle_frame_production = true;
250 const base::TimeDelta display_refresh_interval = 255 const base::TimeDelta display_refresh_interval =
251 BeginFrameArgs::DefaultInterval(); 256 BeginFrameArgs::DefaultInterval();
252 257
253 output_surface.InitializeBeginFrameEmulation( 258 output_surface.InitializeBeginFrameEmulation(
254 task_runner.get(), 259 task_runner.get(),
255 throttle_frame_production, 260 throttle_frame_production,
256 display_refresh_interval); 261 display_refresh_interval);
257 262
258 output_surface.SetMaxFramesPending(2); 263 output_surface.SetMaxFramesPending(2);
259 output_surface.SetRetroactiveBeginFramePeriod( 264 output_surface.EnableRetroactiveBeginFrameDeadline(false);
260 base::TimeDelta::FromSeconds(-1));
261 265
262 // We should start off with 0 BeginFrames 266 // We should start off with 0 BeginFrames
263 EXPECT_EQ(client.begin_frame_count(), 0); 267 EXPECT_EQ(client.begin_frame_count(), 0);
264 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); 268 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
265 269
266 // We should not have a pending task until a BeginFrame has been requested. 270 // We should not have a pending task until a BeginFrame has been requested.
267 EXPECT_FALSE(task_runner->HasPendingTask()); 271 EXPECT_FALSE(task_runner->HasPendingTask());
268 output_surface.SetNeedsBeginFrame(true); 272 output_surface.SetNeedsBeginFrame(true);
269 EXPECT_TRUE(task_runner->HasPendingTask()); 273 EXPECT_TRUE(task_runner->HasPendingTask());
270 274
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 TestOutputSurface output_surface( 328 TestOutputSurface output_surface(
325 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 329 context3d.PassAs<WebKit::WebGraphicsContext3D>());
326 EXPECT_FALSE(output_surface.HasClientForTesting()); 330 EXPECT_FALSE(output_surface.HasClientForTesting());
327 331
328 FakeOutputSurfaceClient client; 332 FakeOutputSurfaceClient client;
329 EXPECT_TRUE(output_surface.BindToClient(&client)); 333 EXPECT_TRUE(output_surface.BindToClient(&client));
330 EXPECT_TRUE(output_surface.HasClientForTesting()); 334 EXPECT_TRUE(output_surface.HasClientForTesting());
331 EXPECT_FALSE(client.deferred_initialize_called()); 335 EXPECT_FALSE(client.deferred_initialize_called());
332 336
333 output_surface.SetMaxFramesPending(2); 337 output_surface.SetMaxFramesPending(2);
334 338 output_surface.EnableRetroactiveBeginFrameDeadline(true);
335 // Enable retroactive BeginFrames.
336 output_surface.SetRetroactiveBeginFramePeriod(
337 base::TimeDelta::FromSeconds(100000));
338 339
339 // Optimistically injected BeginFrames should be throttled if 340 // Optimistically injected BeginFrames should be throttled if
340 // SetNeedsBeginFrame is false... 341 // SetNeedsBeginFrame is false...
341 output_surface.SetNeedsBeginFrame(false); 342 output_surface.SetNeedsBeginFrame(false);
342 output_surface.BeginFrameForTesting(); 343 output_surface.BeginFrameForTesting();
343 EXPECT_EQ(client.begin_frame_count(), 0); 344 EXPECT_EQ(client.begin_frame_count(), 0);
344 // ...and retroactively triggered by a SetNeedsBeginFrame. 345 // ...and retroactively triggered by a SetNeedsBeginFrame.
345 output_surface.SetNeedsBeginFrame(true); 346 output_surface.SetNeedsBeginFrame(true);
346 EXPECT_EQ(client.begin_frame_count(), 1); 347 EXPECT_EQ(client.begin_frame_count(), 1);
347 348
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby; 412 WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby;
412 context->SetMemoryAllocation(allocation); 413 context->SetMemoryAllocation(allocation);
413 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, 414 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
414 client.memory_policy().priority_cutoff_when_visible); 415 client.memory_policy().priority_cutoff_when_visible);
415 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE, 416 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE,
416 client.memory_policy().priority_cutoff_when_not_visible); 417 client.memory_policy().priority_cutoff_when_not_visible);
417 } 418 }
418 419
419 } // namespace 420 } // namespace
420 } // namespace cc 421 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698