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 29 matching lines...) Expand all Loading... |
40 base::SingleThreadTaskRunner* task_runner, | 40 base::SingleThreadTaskRunner* task_runner, |
41 scoped_ptr<ResourceUpdateQueue> queue, | 41 scoped_ptr<ResourceUpdateQueue> queue, |
42 ResourceProvider* resource_provider) | 42 ResourceProvider* resource_provider) |
43 : client_(client), | 43 : client_(client), |
44 queue_(queue.Pass()), | 44 queue_(queue.Pass()), |
45 resource_provider_(resource_provider), | 45 resource_provider_(resource_provider), |
46 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), | 46 texture_updates_per_tick_(MaxFullUpdatesPerTick(resource_provider)), |
47 first_update_attempt_(true), | 47 first_update_attempt_(true), |
48 task_runner_(task_runner), | 48 task_runner_(task_runner), |
49 task_posted_(false), | 49 task_posted_(false), |
| 50 ready_to_finalize_(false), |
50 weak_factory_(this) {} | 51 weak_factory_(this) {} |
51 | 52 |
52 ResourceUpdateController::~ResourceUpdateController() {} | 53 ResourceUpdateController::~ResourceUpdateController() {} |
53 | 54 |
54 void ResourceUpdateController::PerformMoreUpdates( | 55 void ResourceUpdateController::PerformMoreUpdates( |
55 base::TimeTicks time_limit) { | 56 base::TimeTicks time_limit) { |
56 time_limit_ = time_limit; | 57 time_limit_ = time_limit; |
57 | 58 |
58 // Update already in progress. | 59 // Update already in progress or we are already done. |
59 if (task_posted_) | 60 if (task_posted_ || ready_to_finalize_) |
60 return; | 61 return; |
61 | 62 |
62 // Call UpdateMoreTexturesNow() directly unless it's the first update | 63 // Call UpdateMoreTexturesNow() directly unless it's the first update |
63 // attempt. This ensures that we empty the update queue in a finite | 64 // attempt. This ensures that we empty the update queue in a finite |
64 // amount of time. | 65 // amount of time. |
65 if (!first_update_attempt_) | 66 if (!first_update_attempt_) |
66 UpdateMoreTexturesNow(); | 67 UpdateMoreTexturesNow(); |
67 | 68 |
68 // Post a 0-delay task when no updates were left. When it runs, | 69 // Post a 0-delay task when no updates were left. When it runs, |
69 // ReadyToFinalizeTextureUpdates() will be called. | 70 // ReadyToFinalizeTextureUpdates() will be called. |
(...skipping 28 matching lines...) Expand all Loading... |
98 UpdateTexture(queue_->TakeFirstFullUpload()); | 99 UpdateTexture(queue_->TakeFirstFullUpload()); |
99 | 100 |
100 while (queue_->PartialUploadSize()) | 101 while (queue_->PartialUploadSize()) |
101 UpdateTexture(queue_->TakeFirstPartialUpload()); | 102 UpdateTexture(queue_->TakeFirstPartialUpload()); |
102 | 103 |
103 resource_provider_->FlushUploads(); | 104 resource_provider_->FlushUploads(); |
104 } | 105 } |
105 | 106 |
106 void ResourceUpdateController::OnTimerFired() { | 107 void ResourceUpdateController::OnTimerFired() { |
107 task_posted_ = false; | 108 task_posted_ = false; |
108 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) | 109 if (!UpdateMoreTexturesIfEnoughTimeRemaining()) { |
| 110 ready_to_finalize_ = true; |
109 client_->ReadyToFinalizeTextureUpdates(); | 111 client_->ReadyToFinalizeTextureUpdates(); |
| 112 } |
110 } | 113 } |
111 | 114 |
112 base::TimeTicks ResourceUpdateController::UpdateMoreTexturesCompletionTime() { | 115 base::TimeTicks ResourceUpdateController::UpdateMoreTexturesCompletionTime() { |
113 return resource_provider_->EstimatedUploadCompletionTime( | 116 return resource_provider_->EstimatedUploadCompletionTime( |
114 texture_updates_per_tick_); | 117 texture_updates_per_tick_); |
115 } | 118 } |
116 | 119 |
117 size_t ResourceUpdateController::UpdateMoreTexturesSize() const { | 120 size_t ResourceUpdateController::UpdateMoreTexturesSize() const { |
118 return texture_updates_per_tick_; | 121 return texture_updates_per_tick_; |
119 } | 122 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (!uploads) | 155 if (!uploads) |
153 return; | 156 return; |
154 | 157 |
155 while (queue_->FullUploadSize() && uploads--) | 158 while (queue_->FullUploadSize() && uploads--) |
156 UpdateTexture(queue_->TakeFirstFullUpload()); | 159 UpdateTexture(queue_->TakeFirstFullUpload()); |
157 | 160 |
158 resource_provider_->FlushUploads(); | 161 resource_provider_->FlushUploads(); |
159 } | 162 } |
160 | 163 |
161 } // namespace cc | 164 } // namespace cc |
OLD | NEW |