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

Side by Side Diff: cc/resources/resource_update_controller.cc

Issue 12962007: cc: Chromify resource_update_queue (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 9 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
OLDNEW
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 <limits> 7 #include <limits>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 task_posted_ = true; 100 task_posted_ = true;
101 thread_->PostTask( 101 thread_->PostTask(
102 base::Bind(&ResourceUpdateController::OnTimerFired, 102 base::Bind(&ResourceUpdateController::OnTimerFired,
103 weak_factory_.GetWeakPtr())); 103 weak_factory_.GetWeakPtr()));
104 } 104 }
105 105
106 first_update_attempt_ = false; 106 first_update_attempt_ = false;
107 } 107 }
108 108
109 void ResourceUpdateController::DiscardUploadsToEvictedResources() { 109 void ResourceUpdateController::DiscardUploadsToEvictedResources() {
110 queue_->clearUploadsToEvictedResources(); 110 queue_->ClearUploadsToEvictedResources();
111 } 111 }
112 112
113 void ResourceUpdateController::UpdateTexture(ResourceUpdate update) { 113 void ResourceUpdateController::UpdateTexture(ResourceUpdate update) {
114 if (update.picture) { 114 if (update.picture) {
115 PrioritizedResource* texture = update.texture; 115 PrioritizedResource* texture = update.texture;
116 gfx::Rect picture_rect = update.content_rect; 116 gfx::Rect picture_rect = update.content_rect;
117 gfx::Rect source_rect = update.source_rect; 117 gfx::Rect source_rect = update.source_rect;
118 gfx::Vector2d dest_offset = update.dest_offset; 118 gfx::Vector2d dest_offset = update.dest_offset;
119 119
120 texture->AcquireBackingTexture(resource_provider_); 120 texture->AcquireBackingTexture(resource_provider_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 resource_provider_, 176 resource_provider_,
177 static_cast<const uint8_t*>(update.bitmap->getPixels()), 177 static_cast<const uint8_t*>(update.bitmap->getPixels()),
178 update.content_rect, 178 update.content_rect,
179 update.source_rect, 179 update.source_rect,
180 update.dest_offset); 180 update.dest_offset);
181 update.bitmap->unlockPixels(); 181 update.bitmap->unlockPixels();
182 } 182 }
183 } 183 }
184 184
185 void ResourceUpdateController::Finalize() { 185 void ResourceUpdateController::Finalize() {
186 while (queue_->fullUploadSize()) 186 while (queue_->FullUploadSize())
187 UpdateTexture(queue_->takeFirstFullUpload()); 187 UpdateTexture(queue_->TakeFirstFullUpload());
188 188
189 while (queue_->partialUploadSize()) 189 while (queue_->PartialUploadSize())
190 UpdateTexture(queue_->takeFirstPartialUpload()); 190 UpdateTexture(queue_->TakeFirstPartialUpload());
191 191
192 resource_provider_->FlushUploads(); 192 resource_provider_->FlushUploads();
193 193
194 if (queue_->copySize()) { 194 if (queue_->CopySize()) {
195 TextureCopier* copier = resource_provider_->texture_copier(); 195 TextureCopier* copier = resource_provider_->texture_copier();
196 while (queue_->copySize()) 196 while (queue_->CopySize())
197 copier->CopyTexture(queue_->takeFirstCopy()); 197 copier->CopyTexture(queue_->TakeFirstCopy());
198 198
199 // If we've performed any texture copies, we need to insert a flush 199 // If we've performed any texture copies, we need to insert a flush
200 // here into the compositor context before letting the main thread 200 // here into the compositor context before letting the main thread
201 // proceed as it may make draw calls to the source texture of one of 201 // proceed as it may make draw calls to the source texture of one of
202 // our copy operations. 202 // our copy operations.
203 copier->Flush(); 203 copier->Flush();
204 } 204 }
205 } 205 }
206 206
207 void ResourceUpdateController::OnTimerFired() { 207 void ResourceUpdateController::OnTimerFired() {
(...skipping 19 matching lines...) Expand all
227 } 227 }
228 228
229 base::TimeDelta ResourceUpdateController::PendingUpdateTime() const { 229 base::TimeDelta ResourceUpdateController::PendingUpdateTime() const {
230 base::TimeDelta update_one_resource_time = 230 base::TimeDelta update_one_resource_time =
231 UpdateMoreTexturesTime() / UpdateMoreTexturesSize(); 231 UpdateMoreTexturesTime() / UpdateMoreTexturesSize();
232 return update_one_resource_time * resource_provider_->NumBlockingUploads(); 232 return update_one_resource_time * resource_provider_->NumBlockingUploads();
233 } 233 }
234 234
235 bool ResourceUpdateController::UpdateMoreTexturesIfEnoughTimeRemaining() { 235 bool ResourceUpdateController::UpdateMoreTexturesIfEnoughTimeRemaining() {
236 while (resource_provider_->NumBlockingUploads() < MaxBlockingUpdates()) { 236 while (resource_provider_->NumBlockingUploads() < MaxBlockingUpdates()) {
237 if (!queue_->fullUploadSize()) 237 if (!queue_->FullUploadSize())
238 return false; 238 return false;
239 239
240 if (!time_limit_.is_null()) { 240 if (!time_limit_.is_null()) {
241 // Estimated completion time of all pending updates. 241 // Estimated completion time of all pending updates.
242 base::TimeTicks completion_time = Now() + PendingUpdateTime(); 242 base::TimeTicks completion_time = Now() + PendingUpdateTime();
243 243
244 // Time remaining based on current completion estimate. 244 // Time remaining based on current completion estimate.
245 base::TimeDelta time_remaining = time_limit_ - completion_time; 245 base::TimeDelta time_remaining = time_limit_ - completion_time;
246 246
247 if (time_remaining < UpdateMoreTexturesTime()) 247 if (time_remaining < UpdateMoreTexturesTime())
248 return true; 248 return true;
249 } 249 }
250 250
251 UpdateMoreTexturesNow(); 251 UpdateMoreTexturesNow();
252 } 252 }
253 253
254 task_posted_ = true; 254 task_posted_ = true;
255 thread_->PostDelayedTask( 255 thread_->PostDelayedTask(
256 base::Bind(&ResourceUpdateController::OnTimerFired, 256 base::Bind(&ResourceUpdateController::OnTimerFired,
257 weak_factory_.GetWeakPtr()), 257 weak_factory_.GetWeakPtr()),
258 base::TimeDelta::FromMilliseconds(kUploaderBusyTickRate * 1000)); 258 base::TimeDelta::FromMilliseconds(kUploaderBusyTickRate * 1000));
259 return true; 259 return true;
260 } 260 }
261 261
262 void ResourceUpdateController::UpdateMoreTexturesNow() { 262 void ResourceUpdateController::UpdateMoreTexturesNow() {
263 size_t uploads = std::min( 263 size_t uploads = std::min(
264 queue_->fullUploadSize(), UpdateMoreTexturesSize()); 264 queue_->FullUploadSize(), UpdateMoreTexturesSize());
265 265
266 if (!uploads) 266 if (!uploads)
267 return; 267 return;
268 268
269 while (queue_->fullUploadSize() && uploads--) 269 while (queue_->FullUploadSize() && uploads--)
270 UpdateTexture(queue_->takeFirstFullUpload()); 270 UpdateTexture(queue_->TakeFirstFullUpload());
271 271
272 resource_provider_->FlushUploads(); 272 resource_provider_->FlushUploads();
273 } 273 }
274 274
275 } // namespace cc 275 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/prioritized_resource_unittest.cc ('k') | cc/resources/resource_update_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698