OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/resource_update_controller.h" | 5 #include "cc/resources/resource_update_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "cc/resources/prioritized_resource.h" | 10 #include "cc/resources/prioritized_resource.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 resource_provider_(resource_provider), | 49 resource_provider_(resource_provider), |
50 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), | 50 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), |
51 first_update_attempt_(true), | 51 first_update_attempt_(true), |
52 task_runner_(task_runner), | 52 task_runner_(task_runner), |
53 task_posted_(false), | 53 task_posted_(false), |
54 weak_factory_(this) {} | 54 weak_factory_(this) {} |
55 | 55 |
56 ResourceUpdateController::~ResourceUpdateController() {} | 56 ResourceUpdateController::~ResourceUpdateController() {} |
57 | 57 |
58 void ResourceUpdateController::PerformMoreUpdates( | 58 void ResourceUpdateController::PerformMoreUpdates( |
59 base::TimeTicks time_limit) { | 59 gfx::FrameTime time_limit) { |
60 time_limit_ = time_limit; | 60 time_limit_ = time_limit; |
61 | 61 |
62 // Update already in progress. | 62 // Update already in progress. |
63 if (task_posted_) | 63 if (task_posted_) |
64 return; | 64 return; |
65 | 65 |
66 // Call UpdateMoreTexturesNow() directly unless it's the first update | 66 // Call UpdateMoreTexturesNow() directly unless it's the first update |
67 // attempt. This ensures that we empty the update queue in a finite | 67 // attempt. This ensures that we empty the update queue in a finite |
68 // amount of time. | 68 // amount of time. |
69 if (!first_update_attempt_) | 69 if (!first_update_attempt_) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 resource_provider_->FlushUploads(); | 107 resource_provider_->FlushUploads(); |
108 } | 108 } |
109 | 109 |
110 void ResourceUpdateController::OnTimerFired() { | 110 void ResourceUpdateController::OnTimerFired() { |
111 task_posted_ = false; | 111 task_posted_ = false; |
112 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) | 112 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) |
113 client_->ReadyToFinalizeTextureUpdates(); | 113 client_->ReadyToFinalizeTextureUpdates(); |
114 } | 114 } |
115 | 115 |
116 base::TimeTicks ResourceUpdateController::Now() const { | 116 gfx::FrameTime ResourceUpdateController::Now() const { |
117 return gfx::FrameTime::Now(); | 117 return gfx::FrameTime::Now(); |
118 } | 118 } |
119 | 119 |
120 base::TimeDelta ResourceUpdateController::UpdateMoreTexturesTime() const { | 120 base::TimeDelta ResourceUpdateController::UpdateMoreTexturesTime() const { |
121 return resource_provider_->TextureUpdateTickRate(); | 121 return resource_provider_->TextureUpdateTickRate(); |
122 } | 122 } |
123 | 123 |
124 size_t ResourceUpdateController::UpdateMoreTexturesSize() const { | 124 size_t ResourceUpdateController::UpdateMoreTexturesSize() const { |
125 return texture_updates_per_tick_; | 125 return texture_updates_per_tick_; |
126 } | 126 } |
127 | 127 |
128 size_t ResourceUpdateController::MaxBlockingUpdates() const { | 128 size_t ResourceUpdateController::MaxBlockingUpdates() const { |
129 return UpdateMoreTexturesSize() * kMaxBlockingUpdateIntervals; | 129 return UpdateMoreTexturesSize() * kMaxBlockingUpdateIntervals; |
130 } | 130 } |
131 | 131 |
132 base::TimeDelta ResourceUpdateController::PendingUpdateTime() const { | 132 base::TimeDelta ResourceUpdateController::PendingUpdateTime() const { |
133 base::TimeDelta update_one_resource_time = | 133 base::TimeDelta update_one_resource_time = |
134 UpdateMoreTexturesTime() / UpdateMoreTexturesSize(); | 134 UpdateMoreTexturesTime() / UpdateMoreTexturesSize(); |
135 return update_one_resource_time * resource_provider_->NumBlockingUploads(); | 135 return update_one_resource_time * resource_provider_->NumBlockingUploads(); |
136 } | 136 } |
137 | 137 |
138 bool ResourceUpdateController::UpdateMoreTexturesIfEnoughTimeRemaining() { | 138 bool ResourceUpdateController::UpdateMoreTexturesIfEnoughTimeRemaining() { |
139 while (resource_provider_->NumBlockingUploads() < MaxBlockingUpdates()) { | 139 while (resource_provider_->NumBlockingUploads() < MaxBlockingUpdates()) { |
140 if (!queue_->FullUploadSize()) | 140 if (!queue_->FullUploadSize()) |
141 return false; | 141 return false; |
142 | 142 |
143 if (!time_limit_.is_null()) { | 143 if (!time_limit_.is_null()) { |
144 // Estimated completion time of all pending updates. | 144 // Estimated completion time of all pending updates. |
145 base::TimeTicks completion_time = Now() + PendingUpdateTime(); | 145 gfx::FrameTime completion_time = |
| 146 Now() + PendingUpdateTime(); |
146 | 147 |
147 // Time remaining based on current completion estimate. | 148 // Time remaining based on current completion estimate. |
148 base::TimeDelta time_remaining = time_limit_ - completion_time; | 149 base::TimeDelta time_remaining = time_limit_ - completion_time; |
149 | 150 |
150 if (time_remaining < UpdateMoreTexturesTime()) | 151 if (time_remaining < UpdateMoreTexturesTime()) |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 UpdateMoreTexturesNow(); | 155 UpdateMoreTexturesNow(); |
155 } | 156 } |
(...skipping 14 matching lines...) Expand all Loading... |
170 if (!uploads) | 171 if (!uploads) |
171 return; | 172 return; |
172 | 173 |
173 while (queue_->FullUploadSize() && uploads--) | 174 while (queue_->FullUploadSize() && uploads--) |
174 UpdateTexture(queue_->TakeFirstFullUpload()); | 175 UpdateTexture(queue_->TakeFirstFullUpload()); |
175 | 176 |
176 resource_provider_->FlushUploads(); | 177 resource_provider_->FlushUploads(); |
177 } | 178 } |
178 | 179 |
179 } // namespace cc | 180 } // namespace cc |
OLD | NEW |