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

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: Fixed all existing tests! New tests pending... 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 "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/output/managed_memory_policy.h" 8 #include "cc/output/managed_memory_policy.h"
9 #include "cc/output/output_surface_client.h" 9 #include "cc/output/output_surface_client.h"
10 #include "cc/output/software_output_device.h" 10 #include "cc/output/software_output_device.h"
11 #include "cc/test/fake_output_surface.h" 11 #include "cc/test/fake_output_surface.h"
12 #include "cc/test/fake_output_surface_client.h" 12 #include "cc/test/fake_output_surface_client.h"
13 #include "cc/test/scheduler_test_common.h" 13 #include "cc/test/scheduler_test_common.h"
14 #include "cc/test/test_web_graphics_context_3d.h" 14 #include "cc/test/test_web_graphics_context_3d.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) {}
28 29
29 explicit TestOutputSurface( 30 explicit TestOutputSurface(
30 scoped_ptr<cc::SoftwareOutputDevice> software_device) 31 scoped_ptr<cc::SoftwareOutputDevice> software_device)
31 : OutputSurface(software_device.Pass()) {} 32 : OutputSurface(software_device.Pass()),
33 retroactive_begin_frame_deadline_enabled_(false) {}
32 34
33 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 35 TestOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
34 scoped_ptr<cc::SoftwareOutputDevice> software_device) 36 scoped_ptr<cc::SoftwareOutputDevice> software_device)
35 : OutputSurface(context3d.Pass(), software_device.Pass()) {} 37 : OutputSurface(context3d.Pass(), software_device.Pass()),
38 retroactive_begin_frame_deadline_enabled_(false) {}
36 39
37 bool InitializeNewContext3D( 40 bool InitializeNewContext3D(
38 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) { 41 scoped_ptr<WebKit::WebGraphicsContext3D> new_context3d) {
39 return InitializeAndSetContext3D(new_context3d.Pass(), 42 return InitializeAndSetContext3D(new_context3d.Pass(),
40 scoped_refptr<ContextProvider>()); 43 scoped_refptr<ContextProvider>());
41 } 44 }
42 45
43 using OutputSurface::ReleaseGL; 46 using OutputSurface::ReleaseGL;
44 47
45 bool HasClientForTesting() { 48 bool HasClientForTesting() {
(...skipping 14 matching lines...) Expand all
60 } 63 }
61 64
62 int pending_swap_buffers() { 65 int pending_swap_buffers() {
63 return pending_swap_buffers_; 66 return pending_swap_buffers_;
64 } 67 }
65 68
66 void OnSwapBuffersCompleteForTesting() { 69 void OnSwapBuffersCompleteForTesting() {
67 OnSwapBuffersComplete(NULL); 70 OnSwapBuffersComplete(NULL);
68 } 71 }
69 72
70 void SetRetroactiveBeginFramePeriod(base::TimeDelta period) { 73 void EnableRetroactiveBeginFrameDeadline(bool enable) {
71 retroactive_begin_frame_period_ = period; 74 retroactive_begin_frame_deadline_enabled_ = enable;
72 } 75 }
73 76
74 protected: 77 protected:
75 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE { 78 virtual void PostCheckForRetroactiveBeginFrame() OVERRIDE {
76 // For testing purposes, we check immediately rather than posting a task. 79 // For testing purposes, we check immediately rather than posting a task.
77 CheckForRetroactiveBeginFrame(); 80 CheckForRetroactiveBeginFrame();
78 } 81 }
79 82
80 virtual base::TimeDelta RetroactiveBeginFramePeriod() OVERRIDE { 83 virtual base::TimeTicks RetroactiveBeginFrameDeadline() OVERRIDE {
81 return retroactive_begin_frame_period_; 84 if (retroactive_begin_frame_deadline_enabled_)
85 return OutputSurface::RetroactiveBeginFrameDeadline();
86 return base::TimeTicks();
82 } 87 }
83 88
84 base::TimeDelta retroactive_begin_frame_period_; 89 bool retroactive_begin_frame_deadline_enabled_;
85 }; 90 };
86 91
87 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) { 92 TEST(OutputSurfaceTest, ClientPointerIndicatesBindToClientSuccess) {
88 scoped_ptr<TestWebGraphicsContext3D> context3d = 93 scoped_ptr<TestWebGraphicsContext3D> context3d =
89 TestWebGraphicsContext3D::Create(); 94 TestWebGraphicsContext3D::Create();
90 95
91 TestOutputSurface output_surface( 96 TestOutputSurface output_surface(
92 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 97 context3d.PassAs<WebKit::WebGraphicsContext3D>());
93 EXPECT_FALSE(output_surface.HasClientForTesting()); 98 EXPECT_FALSE(output_surface.HasClientForTesting());
94 99
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool throttle_frame_production = true; 200 bool throttle_frame_production = true;
196 const base::TimeDelta display_refresh_interval = 201 const base::TimeDelta display_refresh_interval =
197 BeginFrameArgs::DefaultInterval(); 202 BeginFrameArgs::DefaultInterval();
198 203
199 output_surface.InitializeBeginFrameEmulation( 204 output_surface.InitializeBeginFrameEmulation(
200 task_runner.get(), 205 task_runner.get(),
201 throttle_frame_production, 206 throttle_frame_production,
202 display_refresh_interval); 207 display_refresh_interval);
203 208
204 output_surface.SetMaxFramesPending(2); 209 output_surface.SetMaxFramesPending(2);
205 output_surface.SetRetroactiveBeginFramePeriod( 210 output_surface.EnableRetroactiveBeginFrameDeadline(false);
206 base::TimeDelta::FromSeconds(-1));
207 211
208 // We should start off with 0 BeginFrames 212 // We should start off with 0 BeginFrames
209 EXPECT_EQ(client.begin_frame_count(), 0); 213 EXPECT_EQ(client.begin_frame_count(), 0);
210 EXPECT_EQ(output_surface.pending_swap_buffers(), 0); 214 EXPECT_EQ(output_surface.pending_swap_buffers(), 0);
211 215
212 // We should not have a pending task until a BeginFrame has been requested. 216 // We should not have a pending task until a BeginFrame has been requested.
213 EXPECT_FALSE(task_runner->HasPendingTask()); 217 EXPECT_FALSE(task_runner->HasPendingTask());
214 output_surface.SetNeedsBeginFrame(true); 218 output_surface.SetNeedsBeginFrame(true);
215 EXPECT_TRUE(task_runner->HasPendingTask()); 219 EXPECT_TRUE(task_runner->HasPendingTask());
216 220
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 TestOutputSurface output_surface( 274 TestOutputSurface output_surface(
271 context3d.PassAs<WebKit::WebGraphicsContext3D>()); 275 context3d.PassAs<WebKit::WebGraphicsContext3D>());
272 EXPECT_FALSE(output_surface.HasClientForTesting()); 276 EXPECT_FALSE(output_surface.HasClientForTesting());
273 277
274 FakeOutputSurfaceClient client; 278 FakeOutputSurfaceClient client;
275 EXPECT_TRUE(output_surface.BindToClient(&client)); 279 EXPECT_TRUE(output_surface.BindToClient(&client));
276 EXPECT_TRUE(output_surface.HasClientForTesting()); 280 EXPECT_TRUE(output_surface.HasClientForTesting());
277 EXPECT_FALSE(client.deferred_initialize_called()); 281 EXPECT_FALSE(client.deferred_initialize_called());
278 282
279 output_surface.SetMaxFramesPending(2); 283 output_surface.SetMaxFramesPending(2);
280 284 output_surface.EnableRetroactiveBeginFrameDeadline(true);
281 // Enable retroactive BeginFrames.
282 output_surface.SetRetroactiveBeginFramePeriod(
283 base::TimeDelta::FromSeconds(100000));
284 285
285 // Optimistically injected BeginFrames should be throttled if 286 // Optimistically injected BeginFrames should be throttled if
286 // SetNeedsBeginFrame is false... 287 // SetNeedsBeginFrame is false...
287 output_surface.SetNeedsBeginFrame(false); 288 output_surface.SetNeedsBeginFrame(false);
288 output_surface.BeginFrameForTesting(); 289 output_surface.BeginFrameForTesting();
289 EXPECT_EQ(client.begin_frame_count(), 0); 290 EXPECT_EQ(client.begin_frame_count(), 0);
290 // ...and retroactively triggered by a SetNeedsBeginFrame. 291 // ...and retroactively triggered by a SetNeedsBeginFrame.
291 output_surface.SetNeedsBeginFrame(true); 292 output_surface.SetNeedsBeginFrame(true);
292 EXPECT_EQ(client.begin_frame_count(), 1); 293 EXPECT_EQ(client.begin_frame_count(), 1);
293 294
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby; 358 WebGraphicsMemoryAllocation::PriorityCutoffAllowVisibleAndNearby;
358 context->SetMemoryAllocation(allocation); 359 context->SetMemoryAllocation(allocation);
359 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING, 360 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_EVERYTHING,
360 client.memory_policy().priority_cutoff_when_visible); 361 client.memory_policy().priority_cutoff_when_visible);
361 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE, 362 EXPECT_EQ(ManagedMemoryPolicy::CUTOFF_ALLOW_NICE_TO_HAVE,
362 client.memory_policy().priority_cutoff_when_not_visible); 363 client.memory_policy().priority_cutoff_when_not_visible);
363 } 364 }
364 365
365 } // namespace 366 } // namespace
366 } // namespace cc 367 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698