Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 namespace cc { | 33 namespace cc { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 class FakeSchedulerClient; | 36 class FakeSchedulerClient; |
| 37 | 37 |
| 38 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 38 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 39 FakeSchedulerClient* client); | 39 FakeSchedulerClient* client); |
| 40 | 40 |
| 41 class FakeSchedulerClient : public SchedulerClient { | 41 class FakeSchedulerClient : public SchedulerClient { |
| 42 public: | 42 public: |
| 43 FakeSchedulerClient() : needs_begin_frame_(false), automatic_swap_ack_(true) { | 43 FakeSchedulerClient() : needs_begin_frame_(false), |
| 44 automatic_swap_ack_(true), | |
| 45 contain_incomplete_tile_(false) { | |
|
brianderson
2014/05/27 21:15:57
swap_contains_incomplete_tile_
simonhong
2014/05/28 00:09:35
Done.
| |
| 44 Reset(); | 46 Reset(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 void Reset() { | 49 void Reset() { |
| 48 actions_.clear(); | 50 actions_.clear(); |
| 49 states_.clear(); | 51 states_.clear(); |
| 50 draw_will_happen_ = true; | 52 draw_will_happen_ = true; |
| 51 swap_will_happen_if_draw_happens_ = true; | 53 swap_will_happen_if_draw_happens_ = true; |
| 52 num_draws_ = 0; | 54 num_draws_ = 0; |
| 53 log_anticipated_draw_time_change_ = false; | 55 log_anticipated_draw_time_change_ = false; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 75 | 77 |
| 76 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } | 78 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; } |
| 77 | 79 |
| 78 int ActionIndex(const char* action) const { | 80 int ActionIndex(const char* action) const { |
| 79 for (size_t i = 0; i < actions_.size(); i++) | 81 for (size_t i = 0; i < actions_.size(); i++) |
| 80 if (!strcmp(actions_[i], action)) | 82 if (!strcmp(actions_[i], action)) |
| 81 return i; | 83 return i; |
| 82 return -1; | 84 return -1; |
| 83 } | 85 } |
| 84 | 86 |
| 87 void set_contain_incomplete_tile(bool contain) { | |
|
brianderson
2014/05/27 21:15:57
SetSwapContainsIncompleteTile
simonhong
2014/05/28 00:09:35
Done.
| |
| 88 contain_incomplete_tile_ = contain; | |
| 89 } | |
| 90 | |
| 85 bool HasAction(const char* action) const { | 91 bool HasAction(const char* action) const { |
| 86 return ActionIndex(action) >= 0; | 92 return ActionIndex(action) >= 0; |
| 87 } | 93 } |
| 88 | 94 |
| 89 void SetDrawWillHappen(bool draw_will_happen) { | 95 void SetDrawWillHappen(bool draw_will_happen) { |
| 90 draw_will_happen_ = draw_will_happen; | 96 draw_will_happen_ = draw_will_happen; |
| 91 } | 97 } |
| 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 98 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 99 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 94 } | 100 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 176 |
| 171 virtual void DidBeginImplFrameDeadline() OVERRIDE {} | 177 virtual void DidBeginImplFrameDeadline() OVERRIDE {} |
| 172 | 178 |
| 173 protected: | 179 protected: |
| 174 bool needs_begin_frame_; | 180 bool needs_begin_frame_; |
| 175 bool draw_will_happen_; | 181 bool draw_will_happen_; |
| 176 bool swap_will_happen_if_draw_happens_; | 182 bool swap_will_happen_if_draw_happens_; |
| 177 bool automatic_swap_ack_; | 183 bool automatic_swap_ack_; |
| 178 int num_draws_; | 184 int num_draws_; |
| 179 bool log_anticipated_draw_time_change_; | 185 bool log_anticipated_draw_time_change_; |
| 186 bool contain_incomplete_tile_; | |
|
brianderson
2014/05/27 21:15:57
This isn't used by the base class. Can you put it
simonhong
2014/05/28 00:09:35
Ah.. yes.
SchedulerClientNeedsUpdateVisibleTiles i
| |
| 180 base::TimeTicks posted_begin_impl_frame_deadline_; | 187 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 181 std::vector<const char*> actions_; | 188 std::vector<const char*> actions_; |
| 182 ScopedVector<base::Value> states_; | 189 ScopedVector<base::Value> states_; |
| 183 scoped_ptr<Scheduler> scheduler_; | 190 scoped_ptr<Scheduler> scheduler_; |
| 184 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 191 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 185 }; | 192 }; |
| 186 | 193 |
| 187 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 194 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 188 FakeSchedulerClient* client) { | 195 FakeSchedulerClient* client) { |
| 189 bool client_initiates_begin_frame = | 196 bool client_initiates_begin_frame = |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 875 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 869 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 876 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 877 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 871 client.ActionIndex("ScheduledActionManageTiles")); | 878 client.ActionIndex("ScheduledActionManageTiles")); |
| 872 EXPECT_FALSE(scheduler->RedrawPending()); | 879 EXPECT_FALSE(scheduler->RedrawPending()); |
| 873 EXPECT_FALSE(scheduler->ManageTilesPending()); | 880 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 881 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 875 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 882 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
| 876 } | 883 } |
| 877 | 884 |
| 885 class SchedulerClientNeedsUpdateVisibleTiles : public FakeSchedulerClient { | |
| 886 public: | |
| 887 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | |
| 888 OVERRIDE { | |
| 889 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | |
| 890 states_.push_back(scheduler_->AsValue().release()); | |
| 891 num_draws_++; | |
| 892 DrawResult result = | |
| 893 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | |
| 894 bool swap_will_happen = | |
| 895 draw_will_happen_ && swap_will_happen_if_draw_happens_; | |
| 896 if (swap_will_happen) { | |
| 897 scheduler_->DidSwapBuffers(); | |
| 898 if (contain_incomplete_tile_) { | |
| 899 scheduler_->SetSwapUsedIncompleteTile(true); | |
| 900 contain_incomplete_tile_ = false; | |
| 901 } | |
| 902 if (automatic_swap_ack_) | |
| 903 scheduler_->DidSwapBuffersComplete(); | |
| 904 } | |
| 905 return result; | |
| 906 } | |
| 907 }; | |
| 908 | |
| 909 TEST(SchedulerTest, ShouldUpdateVisibleTiles) { | |
| 910 SchedulerClientNeedsUpdateVisibleTiles client; | |
| 911 SchedulerSettings scheduler_settings; | |
| 912 scheduler_settings.impl_side_painting = true; | |
| 913 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 914 scheduler->SetCanStart(); | |
| 915 scheduler->SetVisible(true); | |
| 916 scheduler->SetCanDraw(true); | |
| 917 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | |
| 918 | |
| 919 // SetNeedsCommit should begin the frame. | |
| 920 client.Reset(); | |
| 921 scheduler->SetNeedsCommit(); | |
| 922 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | |
| 923 | |
| 924 client.Reset(); | |
| 925 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | |
| 926 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | |
| 927 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | |
| 928 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 929 | |
| 930 client.Reset(); | |
| 931 scheduler->NotifyBeginMainFrameStarted(); | |
| 932 scheduler->NotifyReadyToCommit(); | |
| 933 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | |
| 934 | |
| 935 client.Reset(); | |
| 936 scheduler->NotifyReadyToActivate(); | |
| 937 EXPECT_SINGLE_ACTION("ScheduledActionActivatePendingTree", client); | |
| 938 | |
| 939 client.Reset(); | |
| 940 client.set_contain_incomplete_tile(true); | |
| 941 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
| 942 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 3); | |
| 943 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 3); | |
| 944 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 2, 3); | |
|
brianderson
2014/05/27 21:15:57
After this point, can you check that needs_redraw
| |
| 945 } | |
| 946 | |
| 878 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 947 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 879 SchedulerClientNeedsManageTilesInDraw client; | 948 SchedulerClientNeedsManageTilesInDraw client; |
| 880 SchedulerSettings default_scheduler_settings; | 949 SchedulerSettings default_scheduler_settings; |
| 881 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 950 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 882 scheduler->SetCanStart(); | 951 scheduler->SetCanStart(); |
| 883 scheduler->SetVisible(true); | 952 scheduler->SetVisible(true); |
| 884 scheduler->SetCanDraw(true); | 953 scheduler->SetCanDraw(true); |
| 885 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 954 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 886 | 955 |
| 887 client.Reset(); | 956 client.Reset(); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1414 TEST(SchedulerTest, | 1483 TEST(SchedulerTest, |
| 1415 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1484 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
| 1416 bool begin_frame_scheduling_enabled = false; | 1485 bool begin_frame_scheduling_enabled = false; |
| 1417 bool throttle_frame_production = false; | 1486 bool throttle_frame_production = false; |
| 1418 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1487 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1419 throttle_frame_production); | 1488 throttle_frame_production); |
| 1420 } | 1489 } |
| 1421 | 1490 |
| 1422 } // namespace | 1491 } // namespace |
| 1423 } // namespace cc | 1492 } // namespace cc |
| OLD | NEW |