| 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 "cc/base/thread.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 9 #include "cc/output/texture_copier.h" | 10 #include "cc/output/texture_copier.h" |
| 10 #include "cc/resources/prioritized_resource.h" | 11 #include "cc/resources/prioritized_resource.h" |
| 11 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Number of partial updates we allow. | 16 // Number of partial updates we allow. |
| 16 const size_t kPartialTextureUpdatesMax = 12; | 17 const size_t kPartialTextureUpdatesMax = 12; |
| 17 | 18 |
| 18 // Measured in seconds. | 19 // Measured in seconds. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 size_t ResourceUpdateController::MaxFullUpdatesPerTick( | 36 size_t ResourceUpdateController::MaxFullUpdatesPerTick( |
| 36 ResourceProvider* resource_provider) { | 37 ResourceProvider* resource_provider) { |
| 37 double textures_per_second = resource_provider->EstimatedUploadsPerSecond(); | 38 double textures_per_second = resource_provider->EstimatedUploadsPerSecond(); |
| 38 size_t textures_per_tick = | 39 size_t textures_per_tick = |
| 39 floor(kTextureUpdateTickRate * textures_per_second); | 40 floor(kTextureUpdateTickRate * textures_per_second); |
| 40 return textures_per_tick ? textures_per_tick : 1; | 41 return textures_per_tick ? textures_per_tick : 1; |
| 41 } | 42 } |
| 42 | 43 |
| 43 ResourceUpdateController::ResourceUpdateController( | 44 ResourceUpdateController::ResourceUpdateController( |
| 44 ResourceUpdateControllerClient* client, | 45 ResourceUpdateControllerClient* client, |
| 45 Thread* thread, | 46 base::SingleThreadTaskRunner* task_runner, |
| 46 scoped_ptr<ResourceUpdateQueue> queue, | 47 scoped_ptr<ResourceUpdateQueue> queue, |
| 47 ResourceProvider* resource_provider) | 48 ResourceProvider* resource_provider) |
| 48 : client_(client), | 49 : client_(client), |
| 49 queue_(queue.Pass()), | 50 queue_(queue.Pass()), |
| 50 resource_provider_(resource_provider), | 51 resource_provider_(resource_provider), |
| 51 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), | 52 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), |
| 52 first_update_attempt_(true), | 53 first_update_attempt_(true), |
| 53 thread_(thread), | 54 task_runner_(task_runner), |
| 54 weak_factory_(this), | 55 weak_factory_(this), |
| 55 task_posted_(false) {} | 56 task_posted_(false) {} |
| 56 | 57 |
| 57 ResourceUpdateController::~ResourceUpdateController() {} | 58 ResourceUpdateController::~ResourceUpdateController() {} |
| 58 | 59 |
| 59 void ResourceUpdateController::PerformMoreUpdates( | 60 void ResourceUpdateController::PerformMoreUpdates( |
| 60 base::TimeTicks time_limit) { | 61 base::TimeTicks time_limit) { |
| 61 time_limit_ = time_limit; | 62 time_limit_ = time_limit; |
| 62 | 63 |
| 63 // Update already in progress. | 64 // Update already in progress. |
| 64 if (task_posted_) | 65 if (task_posted_) |
| 65 return; | 66 return; |
| 66 | 67 |
| 67 // Call UpdateMoreTexturesNow() directly unless it's the first update | 68 // Call UpdateMoreTexturesNow() directly unless it's the first update |
| 68 // attempt. This ensures that we empty the update queue in a finite | 69 // attempt. This ensures that we empty the update queue in a finite |
| 69 // amount of time. | 70 // amount of time. |
| 70 if (!first_update_attempt_) | 71 if (!first_update_attempt_) |
| 71 UpdateMoreTexturesNow(); | 72 UpdateMoreTexturesNow(); |
| 72 | 73 |
| 73 // Post a 0-delay task when no updates were left. When it runs, | 74 // Post a 0-delay task when no updates were left. When it runs, |
| 74 // ReadyToFinalizeTextureUpdates() will be called. | 75 // ReadyToFinalizeTextureUpdates() will be called. |
| 75 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) { | 76 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) { |
| 76 task_posted_ = true; | 77 task_posted_ = true; |
| 77 thread_->PostTask( | 78 task_runner_->PostTask( |
| 79 FROM_HERE, |
| 78 base::Bind(&ResourceUpdateController::OnTimerFired, | 80 base::Bind(&ResourceUpdateController::OnTimerFired, |
| 79 weak_factory_.GetWeakPtr())); | 81 weak_factory_.GetWeakPtr())); |
| 80 } | 82 } |
| 81 | 83 |
| 82 first_update_attempt_ = false; | 84 first_update_attempt_ = false; |
| 83 } | 85 } |
| 84 | 86 |
| 85 void ResourceUpdateController::DiscardUploadsToEvictedResources() { | 87 void ResourceUpdateController::DiscardUploadsToEvictedResources() { |
| 86 queue_->ClearUploadsToEvictedResources(); | 88 queue_->ClearUploadsToEvictedResources(); |
| 87 } | 89 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 base::TimeDelta time_remaining = time_limit_ - completion_time; | 162 base::TimeDelta time_remaining = time_limit_ - completion_time; |
| 161 | 163 |
| 162 if (time_remaining < UpdateMoreTexturesTime()) | 164 if (time_remaining < UpdateMoreTexturesTime()) |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 166 UpdateMoreTexturesNow(); | 168 UpdateMoreTexturesNow(); |
| 167 } | 169 } |
| 168 | 170 |
| 169 task_posted_ = true; | 171 task_posted_ = true; |
| 170 thread_->PostDelayedTask( | 172 task_runner_->PostDelayedTask( |
| 173 FROM_HERE, |
| 171 base::Bind(&ResourceUpdateController::OnTimerFired, | 174 base::Bind(&ResourceUpdateController::OnTimerFired, |
| 172 weak_factory_.GetWeakPtr()), | 175 weak_factory_.GetWeakPtr()), |
| 173 base::TimeDelta::FromMilliseconds(kUploaderBusyTickRate * 1000)); | 176 base::TimeDelta::FromMilliseconds(kUploaderBusyTickRate * 1000)); |
| 174 return true; | 177 return true; |
| 175 } | 178 } |
| 176 | 179 |
| 177 void ResourceUpdateController::UpdateMoreTexturesNow() { | 180 void ResourceUpdateController::UpdateMoreTexturesNow() { |
| 178 size_t uploads = std::min( | 181 size_t uploads = std::min( |
| 179 queue_->FullUploadSize(), UpdateMoreTexturesSize()); | 182 queue_->FullUploadSize(), UpdateMoreTexturesSize()); |
| 180 | 183 |
| 181 if (!uploads) | 184 if (!uploads) |
| 182 return; | 185 return; |
| 183 | 186 |
| 184 while (queue_->FullUploadSize() && uploads--) | 187 while (queue_->FullUploadSize() && uploads--) |
| 185 UpdateTexture(queue_->TakeFirstFullUpload()); | 188 UpdateTexture(queue_->TakeFirstFullUpload()); |
| 186 | 189 |
| 187 resource_provider_->FlushUploads(); | 190 resource_provider_->FlushUploads(); |
| 188 } | 191 } |
| 189 | 192 |
| 190 } // namespace cc | 193 } // namespace cc |
| OLD | NEW |