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

Side by Side Diff: cc/resource_update_controller.cc

Issue 11270047: cc: Rename TextureUpdate to ResourceUpdate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort includes and forward declarations. Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « cc/resource_update_controller.h ('k') | cc/resource_update_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/texture_update_controller.h" 7 #include "cc/resource_update_controller.h"
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/prioritized_texture.h" 10 #include "cc/prioritized_texture.h"
11 #include "cc/proxy.h" 11 #include "cc/proxy.h"
12 #include "cc/resource_provider.h" 12 #include "cc/resource_provider.h"
13 #include "cc/texture_copier.h" 13 #include "cc/texture_copier.h"
14 #include "third_party/khronos/GLES2/gl2.h" 14 #include "third_party/khronos/GLES2/gl2.h"
15 #include "third_party/skia/include/gpu/SkGpuDevice.h" 15 #include "third_party/skia/include/gpu/SkGpuDevice.h"
16 #include <limits> 16 #include <limits>
17 #include <public/WebGraphicsContext3D.h> 17 #include <public/WebGraphicsContext3D.h>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 SkAutoTUnref<GrTexture> target( 50 SkAutoTUnref<GrTexture> target(
51 grContext->createPlatformTexture(textureDesc)); 51 grContext->createPlatformTexture(textureDesc));
52 SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get())); 52 SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get()));
53 return make_scoped_ptr(new SkCanvas(device.get())); 53 return make_scoped_ptr(new SkCanvas(device.get()));
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 namespace cc { 58 namespace cc {
59 59
60 size_t TextureUpdateController::maxPartialTextureUpdates() 60 size_t ResourceUpdateController::maxPartialTextureUpdates()
61 { 61 {
62 return partialTextureUpdatesMax; 62 return partialTextureUpdatesMax;
63 } 63 }
64 64
65 size_t TextureUpdateController::maxFullUpdatesPerTick( 65 size_t ResourceUpdateController::maxFullUpdatesPerTick(
66 ResourceProvider* resourceProvider) 66 ResourceProvider* resourceProvider)
67 { 67 {
68 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond(); 68 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond();
69 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); 69 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond);
70 return texturesPerTick ? texturesPerTick : 1; 70 return texturesPerTick ? texturesPerTick : 1;
71 } 71 }
72 72
73 TextureUpdateController::TextureUpdateController(TextureUpdateControllerClient* client, Thread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceProvider) 73 ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClien t* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvid er* resourceProvider)
74 : m_client(client) 74 : m_client(client)
75 , m_timer(new Timer(thread, this)) 75 , m_timer(new Timer(thread, this))
76 , m_queue(queue.Pass()) 76 , m_queue(queue.Pass())
77 , m_resourceProvider(resourceProvider) 77 , m_resourceProvider(resourceProvider)
78 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) 78 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider))
79 , m_firstUpdateAttempt(true) 79 , m_firstUpdateAttempt(true)
80 { 80 {
81 } 81 }
82 82
83 TextureUpdateController::~TextureUpdateController() 83 ResourceUpdateController::~ResourceUpdateController()
84 { 84 {
85 } 85 }
86 86
87 void TextureUpdateController::performMoreUpdates( 87 void ResourceUpdateController::performMoreUpdates(
88 base::TimeTicks timeLimit) 88 base::TimeTicks timeLimit)
89 { 89 {
90 m_timeLimit = timeLimit; 90 m_timeLimit = timeLimit;
91 91
92 // Update already in progress. 92 // Update already in progress.
93 if (m_timer->isActive()) 93 if (m_timer->isActive())
94 return; 94 return;
95 95
96 // Call updateMoreTexturesNow() directly unless it's the first update 96 // Call updateMoreTexturesNow() directly unless it's the first update
97 // attempt. This ensures that we empty the update queue in a finite 97 // attempt. This ensures that we empty the update queue in a finite
98 // amount of time. 98 // amount of time.
99 if (m_firstUpdateAttempt) { 99 if (m_firstUpdateAttempt) {
100 // Post a 0-delay task when no updates were left. When it runs, 100 // Post a 0-delay task when no updates were left. When it runs,
101 // readyToFinalizeTextureUpdates() will be called. 101 // readyToFinalizeTextureUpdates() will be called.
102 if (!updateMoreTexturesIfEnoughTimeRemaining()) 102 if (!updateMoreTexturesIfEnoughTimeRemaining())
103 m_timer->startOneShot(0); 103 m_timer->startOneShot(0);
104 104
105 m_firstUpdateAttempt = false; 105 m_firstUpdateAttempt = false;
106 } else 106 } else
107 updateMoreTexturesNow(); 107 updateMoreTexturesNow();
108 } 108 }
109 109
110 void TextureUpdateController::discardUploadsToEvictedResources() 110 void ResourceUpdateController::discardUploadsToEvictedResources()
111 { 111 {
112 m_queue->clearUploadsToEvictedResources(); 112 m_queue->clearUploadsToEvictedResources();
113 } 113 }
114 114
115 void TextureUpdateController::updateTexture(ResourceUpdate update) 115 void ResourceUpdateController::updateTexture(ResourceUpdate update)
116 { 116 {
117 if (update.picture) { 117 if (update.picture) {
118 PrioritizedTexture* texture = update.texture; 118 PrioritizedTexture* texture = update.texture;
119 IntRect pictureRect = update.content_rect; 119 IntRect pictureRect = update.content_rect;
120 IntRect sourceRect = update.source_rect; 120 IntRect sourceRect = update.source_rect;
121 IntSize destOffset = update.dest_offset; 121 IntSize destOffset = update.dest_offset;
122 122
123 texture->acquireBackingTexture(m_resourceProvider); 123 texture->acquireBackingTexture(m_resourceProvider);
124 DCHECK(texture->haveBackingTexture()); 124 DCHECK(texture->haveBackingTexture());
125 125
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 update.texture->upload( 179 update.texture->upload(
180 m_resourceProvider, 180 m_resourceProvider,
181 static_cast<const uint8_t*>(update.bitmap->getPixels()), 181 static_cast<const uint8_t*>(update.bitmap->getPixels()),
182 update.content_rect, 182 update.content_rect,
183 update.source_rect, 183 update.source_rect,
184 update.dest_offset); 184 update.dest_offset);
185 update.bitmap->unlockPixels(); 185 update.bitmap->unlockPixels();
186 } 186 }
187 } 187 }
188 188
189 void TextureUpdateController::finalize() 189 void ResourceUpdateController::finalize()
190 { 190 {
191 size_t uploadCount = 0; 191 size_t uploadCount = 0;
192 while (m_queue->fullUploadSize()) { 192 while (m_queue->fullUploadSize()) {
193 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) 193 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
194 m_resourceProvider->shallowFlushIfSupported(); 194 m_resourceProvider->shallowFlushIfSupported();
195 195
196 updateTexture(m_queue->takeFirstFullUpload()); 196 updateTexture(m_queue->takeFirstFullUpload());
197 uploadCount++; 197 uploadCount++;
198 } 198 }
199 199
(...skipping 14 matching lines...) Expand all
214 copier->copyTexture(m_queue->takeFirstCopy()); 214 copier->copyTexture(m_queue->takeFirstCopy());
215 215
216 // If we've performed any texture copies, we need to insert a flush 216 // If we've performed any texture copies, we need to insert a flush
217 // here into the compositor context before letting the main thread 217 // here into the compositor context before letting the main thread
218 // proceed as it may make draw calls to the source texture of one of 218 // proceed as it may make draw calls to the source texture of one of
219 // our copy operations. 219 // our copy operations.
220 copier->flush(); 220 copier->flush();
221 } 221 }
222 } 222 }
223 223
224 void TextureUpdateController::onTimerFired() 224 void ResourceUpdateController::onTimerFired()
225 { 225 {
226 ResourceProvider::debugNotifyEnterZone(0xB000000); 226 ResourceProvider::debugNotifyEnterZone(0xB000000);
227 if (!updateMoreTexturesIfEnoughTimeRemaining()) 227 if (!updateMoreTexturesIfEnoughTimeRemaining())
228 m_client->readyToFinalizeTextureUpdates(); 228 m_client->readyToFinalizeTextureUpdates();
229 ResourceProvider::debugNotifyLeaveZone(); 229 ResourceProvider::debugNotifyLeaveZone();
230 } 230 }
231 231
232 base::TimeTicks TextureUpdateController::now() const 232 base::TimeTicks ResourceUpdateController::now() const
233 { 233 {
234 return base::TimeTicks::Now(); 234 return base::TimeTicks::Now();
235 } 235 }
236 236
237 base::TimeDelta TextureUpdateController::updateMoreTexturesTime() const 237 base::TimeDelta ResourceUpdateController::updateMoreTexturesTime() const
238 { 238 {
239 return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000); 239 return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000);
240 } 240 }
241 241
242 size_t TextureUpdateController::updateMoreTexturesSize() const 242 size_t ResourceUpdateController::updateMoreTexturesSize() const
243 { 243 {
244 return m_textureUpdatesPerTick; 244 return m_textureUpdatesPerTick;
245 } 245 }
246 246
247 size_t TextureUpdateController::maxBlockingUpdates() const 247 size_t ResourceUpdateController::maxBlockingUpdates() const
248 { 248 {
249 return updateMoreTexturesSize() * maxBlockingUpdateIntervals; 249 return updateMoreTexturesSize() * maxBlockingUpdateIntervals;
250 } 250 }
251 251
252 bool TextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() 252 bool ResourceUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
253 { 253 {
254 // Blocking uploads will increase when we're too aggressive in our upload 254 // Blocking uploads will increase when we're too aggressive in our upload
255 // time estimate. We use a different timeout here to prevent unnecessary 255 // time estimate. We use a different timeout here to prevent unnecessary
256 // amounts of idle time when blocking uploads have reached the max. 256 // amounts of idle time when blocking uploads have reached the max.
257 if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) { 257 if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) {
258 m_timer->startOneShot(uploaderBusyTickRate); 258 m_timer->startOneShot(uploaderBusyTickRate);
259 return true; 259 return true;
260 } 260 }
261 261
262 if (!m_queue->fullUploadSize()) 262 if (!m_queue->fullUploadSize())
263 return false; 263 return false;
264 264
265 bool hasTimeRemaining = m_timeLimit.is_null() || 265 bool hasTimeRemaining = m_timeLimit.is_null() ||
266 this->now() < m_timeLimit - updateMoreTexturesTime(); 266 this->now() < m_timeLimit - updateMoreTexturesTime();
267 if (hasTimeRemaining) 267 if (hasTimeRemaining)
268 updateMoreTexturesNow(); 268 updateMoreTexturesNow();
269 269
270 return true; 270 return true;
271 } 271 }
272 272
273 void TextureUpdateController::updateMoreTexturesNow() 273 void ResourceUpdateController::updateMoreTexturesNow()
274 { 274 {
275 size_t uploads = std::min( 275 size_t uploads = std::min(
276 m_queue->fullUploadSize(), updateMoreTexturesSize()); 276 m_queue->fullUploadSize(), updateMoreTexturesSize());
277 m_timer->startOneShot( 277 m_timer->startOneShot(
278 updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() * 278 updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() *
279 uploads); 279 uploads);
280 280
281 if (!uploads) 281 if (!uploads)
282 return; 282 return;
283 283
284 size_t uploadCount = 0; 284 size_t uploadCount = 0;
285 while (m_queue->fullUploadSize() && uploadCount < uploads) { 285 while (m_queue->fullUploadSize() && uploadCount < uploads) {
286 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) 286 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
287 m_resourceProvider->shallowFlushIfSupported(); 287 m_resourceProvider->shallowFlushIfSupported();
288 updateTexture(m_queue->takeFirstFullUpload()); 288 updateTexture(m_queue->takeFirstFullUpload());
289 uploadCount++; 289 uploadCount++;
290 } 290 }
291 m_resourceProvider->shallowFlushIfSupported(); 291 m_resourceProvider->shallowFlushIfSupported();
292 } 292 }
293 293
294 } // namespace cc 294 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resource_update_controller.h ('k') | cc/resource_update_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698