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

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

Issue 16863005: cc: Add BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc12
Patch Set: Rebase Created 7 years, 6 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
« no previous file with comments | « cc/output/output_surface_client.h ('k') | cc/scheduler/frame_rate_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/output_surface.h" 6 #include "cc/output/output_surface.h"
7 #include "cc/output/output_surface_client.h" 7 #include "cc/output/output_surface_client.h"
8 #include "cc/output/software_output_device.h" 8 #include "cc/output/software_output_device.h"
9 #include "cc/test/scheduler_test_common.h" 9 #include "cc/test/scheduler_test_common.h"
10 #include "cc/test/test_web_graphics_context_3d.h" 10 #include "cc/test/test_web_graphics_context_3d.h"
(...skipping 24 matching lines...) Expand all
35 35
36 bool HasClientForTesting() { 36 bool HasClientForTesting() {
37 return HasClient(); 37 return HasClient();
38 } 38 }
39 39
40 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase, 40 void OnVSyncParametersChangedForTesting(base::TimeTicks timebase,
41 base::TimeDelta interval) { 41 base::TimeDelta interval) {
42 OnVSyncParametersChanged(timebase, interval); 42 OnVSyncParametersChanged(timebase, interval);
43 } 43 }
44 44
45 void BeginFrameForTesting(base::TimeTicks frame_time) { 45 void BeginFrameForTesting() {
46 BeginFrame(frame_time); 46 BeginFrame(BeginFrameArgs::CreateForTesting());
47 } 47 }
48 48
49 void DidSwapBuffersForTesting() { 49 void DidSwapBuffersForTesting() {
50 DidSwapBuffers(); 50 DidSwapBuffers();
51 } 51 }
52 52
53 int pending_swap_buffers() { 53 int pending_swap_buffers() {
54 return pending_swap_buffers_; 54 return pending_swap_buffers_;
55 } 55 }
56 56
57 void OnSwapBuffersCompleteForTesting() { 57 void OnSwapBuffersCompleteForTesting() {
58 OnSwapBuffersComplete(NULL); 58 OnSwapBuffersComplete(NULL);
59 } 59 }
60 }; 60 };
61 61
62 class FakeOutputSurfaceClient : public OutputSurfaceClient { 62 class FakeOutputSurfaceClient : public OutputSurfaceClient {
63 public: 63 public:
64 FakeOutputSurfaceClient() 64 FakeOutputSurfaceClient()
65 : begin_frame_count_(0), 65 : begin_frame_count_(0),
66 deferred_initialize_result_(true), 66 deferred_initialize_result_(true),
67 deferred_initialize_called_(false), 67 deferred_initialize_called_(false),
68 did_lose_output_surface_called_(false) {} 68 did_lose_output_surface_called_(false) {}
69 69
70 virtual bool DeferredInitialize( 70 virtual bool DeferredInitialize(
71 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE { 71 scoped_refptr<ContextProvider> offscreen_context_provider) OVERRIDE {
72 deferred_initialize_called_ = true; 72 deferred_initialize_called_ = true;
73 return deferred_initialize_result_; 73 return deferred_initialize_result_;
74 } 74 }
75 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {} 75 virtual void SetNeedsRedrawRect(gfx::Rect damage_rect) OVERRIDE {}
76 virtual void BeginFrame(base::TimeTicks frame_time) OVERRIDE { 76 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {
77 begin_frame_count_++; 77 begin_frame_count_++;
78 } 78 }
79 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE {} 79 virtual void OnSwapBuffersComplete(const CompositorFrameAck* ack) OVERRIDE {}
80 virtual void DidLoseOutputSurface() OVERRIDE { 80 virtual void DidLoseOutputSurface() OVERRIDE {
81 did_lose_output_surface_called_ = true; 81 did_lose_output_surface_called_ = true;
82 } 82 }
83 virtual void SetExternalDrawConstraints(const gfx::Transform& transform, 83 virtual void SetExternalDrawConstraints(const gfx::Transform& transform,
84 gfx::Rect viewport) OVERRIDE {} 84 gfx::Rect viewport) OVERRIDE {}
85 85
86 int begin_frame_count() { 86 int begin_frame_count() {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 FakeOutputSurfaceClient client; 206 FakeOutputSurfaceClient client;
207 EXPECT_TRUE(output_surface.BindToClient(&client)); 207 EXPECT_TRUE(output_surface.BindToClient(&client));
208 EXPECT_TRUE(output_surface.HasClientForTesting()); 208 EXPECT_TRUE(output_surface.HasClientForTesting());
209 EXPECT_FALSE(client.deferred_initialize_called()); 209 EXPECT_FALSE(client.deferred_initialize_called());
210 210
211 // Initialize BeginFrame emulation 211 // Initialize BeginFrame emulation
212 scoped_refptr<base::TestSimpleTaskRunner> task_runner = 212 scoped_refptr<base::TestSimpleTaskRunner> task_runner =
213 new base::TestSimpleTaskRunner; 213 new base::TestSimpleTaskRunner;
214 bool throttle_frame_production = true; 214 bool throttle_frame_production = true;
215 const base::TimeDelta display_refresh_interval = 215 const base::TimeDelta display_refresh_interval =
216 base::TimeDelta::FromMicroseconds(16666); 216 BeginFrameArgs::DefaultInterval();
217 217
218 output_surface.InitializeBeginFrameEmulation( 218 output_surface.InitializeBeginFrameEmulation(
219 task_runner.get(), 219 task_runner.get(),
220 throttle_frame_production, 220 throttle_frame_production,
221 display_refresh_interval); 221 display_refresh_interval);
222 222
223 output_surface.SetMaxFramesPending(2); 223 output_surface.SetMaxFramesPending(2);
224 224
225 // We should start off with 0 BeginFrames 225 // We should start off with 0 BeginFrames
226 EXPECT_EQ(client.begin_frame_count(), 0); 226 EXPECT_EQ(client.begin_frame_count(), 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 // Disabling SetNeedsBeginFrame should prevent further BeginFrames. 275 // Disabling SetNeedsBeginFrame should prevent further BeginFrames.
276 output_surface.SetNeedsBeginFrame(false); 276 output_surface.SetNeedsBeginFrame(false);
277 task_runner->RunPendingTasks(); 277 task_runner->RunPendingTasks();
278 EXPECT_FALSE(task_runner->HasPendingTask()); 278 EXPECT_FALSE(task_runner->HasPendingTask());
279 EXPECT_EQ(client.begin_frame_count(), 4); 279 EXPECT_EQ(client.begin_frame_count(), 4);
280 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); 280 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
281 281
282 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should be 282 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should be
283 // allowed. 283 // allowed.
284 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); 284 output_surface.BeginFrameForTesting();
285 EXPECT_EQ(client.begin_frame_count(), 5); 285 EXPECT_EQ(client.begin_frame_count(), 5);
286 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); 286 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
287 287
288 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should 288 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should
289 // still be throttled by pending begin frames however. 289 // still be throttled by pending begin frames however.
290 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); 290 output_surface.BeginFrameForTesting();
291 EXPECT_EQ(client.begin_frame_count(), 5); 291 EXPECT_EQ(client.begin_frame_count(), 5);
292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1); 292 EXPECT_EQ(output_surface.pending_swap_buffers(), 1);
293 293
294 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should 294 // Optimistically injected BeginFrames without a SetNeedsBeginFrame should
295 // also be throttled by pending swap buffers. 295 // also be throttled by pending swap buffers.
296 output_surface.DidSwapBuffersForTesting(); 296 output_surface.DidSwapBuffersForTesting();
297 EXPECT_EQ(client.begin_frame_count(), 5); 297 EXPECT_EQ(client.begin_frame_count(), 5);
298 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); 298 EXPECT_EQ(output_surface.pending_swap_buffers(), 2);
299 output_surface.BeginFrameForTesting(base::TimeTicks::Now()); 299 output_surface.BeginFrameForTesting();
300 EXPECT_EQ(client.begin_frame_count(), 5); 300 EXPECT_EQ(client.begin_frame_count(), 5);
301 EXPECT_EQ(output_surface.pending_swap_buffers(), 2); 301 EXPECT_EQ(output_surface.pending_swap_buffers(), 2);
302 } 302 }
303 303
304 } // namespace 304 } // namespace
305 } // namespace cc 305 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface_client.h ('k') | cc/scheduler/frame_rate_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698