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

Side by Side Diff: cc/resource_update_controller.cc

Issue 11344004: Remove WebKit::Platform dependencies from cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix webkit_compositor_bindings_unittests 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/resource_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 "cc/thread.h"
14 #include "third_party/khronos/GLES2/gl2.h" 15 #include "third_party/khronos/GLES2/gl2.h"
15 #include "third_party/skia/include/gpu/SkGpuDevice.h" 16 #include "third_party/skia/include/gpu/SkGpuDevice.h"
16 #include <limits> 17 #include <limits>
17 #include <public/WebGraphicsContext3D.h> 18 #include <public/WebGraphicsContext3D.h>
18 #include <public/WebSharedGraphicsContext3D.h> 19 #include <public/WebSharedGraphicsContext3D.h>
19 20
20 using WebKit::WebGraphicsContext3D; 21 using WebKit::WebGraphicsContext3D;
21 using WebKit::WebSharedGraphicsContext3D; 22 using WebKit::WebSharedGraphicsContext3D;
22 23
23 namespace { 24 namespace {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 size_t ResourceUpdateController::maxFullUpdatesPerTick( 65 size_t ResourceUpdateController::maxFullUpdatesPerTick(
65 ResourceProvider* resourceProvider) 66 ResourceProvider* resourceProvider)
66 { 67 {
67 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond(); 68 double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond();
68 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); 69 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond);
69 return texturesPerTick ? texturesPerTick : 1; 70 return texturesPerTick ? texturesPerTick : 1;
70 } 71 }
71 72
72 ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClien t* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvid er* resourceProvider) 73 ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClien t* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvid er* resourceProvider)
73 : m_client(client) 74 : m_client(client)
74 , m_timer(new Timer(thread, this))
75 , m_queue(queue.Pass()) 75 , m_queue(queue.Pass())
76 , m_resourceProvider(resourceProvider) 76 , m_resourceProvider(resourceProvider)
77 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) 77 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider))
78 , m_firstUpdateAttempt(true) 78 , m_firstUpdateAttempt(true)
79 , m_thread(thread)
80 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
81 , m_taskPosted(false)
79 { 82 {
80 } 83 }
81 84
82 ResourceUpdateController::~ResourceUpdateController() 85 ResourceUpdateController::~ResourceUpdateController()
83 { 86 {
84 } 87 }
85 88
86 void ResourceUpdateController::performMoreUpdates( 89 void ResourceUpdateController::performMoreUpdates(
87 base::TimeTicks timeLimit) 90 base::TimeTicks timeLimit)
88 { 91 {
89 m_timeLimit = timeLimit; 92 m_timeLimit = timeLimit;
90 93
91 // Update already in progress. 94 // Update already in progress.
92 if (m_timer->isActive()) 95 if (m_taskPosted)
93 return; 96 return;
94 97
95 // Call updateMoreTexturesNow() directly unless it's the first update 98 // Call updateMoreTexturesNow() directly unless it's the first update
96 // attempt. This ensures that we empty the update queue in a finite 99 // attempt. This ensures that we empty the update queue in a finite
97 // amount of time. 100 // amount of time.
98 if (m_firstUpdateAttempt) { 101 if (m_firstUpdateAttempt) {
99 // Post a 0-delay task when no updates were left. When it runs, 102 // Post a 0-delay task when no updates were left. When it runs,
100 // readyToFinalizeTextureUpdates() will be called. 103 // readyToFinalizeTextureUpdates() will be called.
101 if (!updateMoreTexturesIfEnoughTimeRemaining()) 104 if (!updateMoreTexturesIfEnoughTimeRemaining()) {
102 m_timer->startOneShot(0); 105 m_taskPosted = true;
106 m_thread->postTask(base::Bind(&ResourceUpdateController::onTimerFire d,
107 m_weakFactory.GetWeakPtr()));
108 }
103 109
104 m_firstUpdateAttempt = false; 110 m_firstUpdateAttempt = false;
105 } else 111 } else
106 updateMoreTexturesNow(); 112 updateMoreTexturesNow();
107 } 113 }
108 114
109 void ResourceUpdateController::discardUploadsToEvictedResources() 115 void ResourceUpdateController::discardUploadsToEvictedResources()
110 { 116 {
111 m_queue->clearUploadsToEvictedResources(); 117 m_queue->clearUploadsToEvictedResources();
112 } 118 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // If we've performed any texture copies, we need to insert a flush 221 // If we've performed any texture copies, we need to insert a flush
216 // here into the compositor context before letting the main thread 222 // here into the compositor context before letting the main thread
217 // proceed as it may make draw calls to the source texture of one of 223 // proceed as it may make draw calls to the source texture of one of
218 // our copy operations. 224 // our copy operations.
219 copier->flush(); 225 copier->flush();
220 } 226 }
221 } 227 }
222 228
223 void ResourceUpdateController::onTimerFired() 229 void ResourceUpdateController::onTimerFired()
224 { 230 {
231 m_taskPosted = false;
225 ResourceProvider::debugNotifyEnterZone(0xB000000); 232 ResourceProvider::debugNotifyEnterZone(0xB000000);
226 if (!updateMoreTexturesIfEnoughTimeRemaining()) 233 if (!updateMoreTexturesIfEnoughTimeRemaining())
227 m_client->readyToFinalizeTextureUpdates(); 234 m_client->readyToFinalizeTextureUpdates();
228 ResourceProvider::debugNotifyLeaveZone(); 235 ResourceProvider::debugNotifyLeaveZone();
229 } 236 }
230 237
231 base::TimeTicks ResourceUpdateController::now() const 238 base::TimeTicks ResourceUpdateController::now() const
232 { 239 {
233 return base::TimeTicks::Now(); 240 return base::TimeTicks::Now();
234 } 241 }
(...skipping 12 matching lines...) Expand all
247 { 254 {
248 return updateMoreTexturesSize() * maxBlockingUpdateIntervals; 255 return updateMoreTexturesSize() * maxBlockingUpdateIntervals;
249 } 256 }
250 257
251 bool ResourceUpdateController::updateMoreTexturesIfEnoughTimeRemaining() 258 bool ResourceUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
252 { 259 {
253 // Blocking uploads will increase when we're too aggressive in our upload 260 // Blocking uploads will increase when we're too aggressive in our upload
254 // time estimate. We use a different timeout here to prevent unnecessary 261 // time estimate. We use a different timeout here to prevent unnecessary
255 // amounts of idle time when blocking uploads have reached the max. 262 // amounts of idle time when blocking uploads have reached the max.
256 if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) { 263 if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) {
257 m_timer->startOneShot(uploaderBusyTickRate); 264 m_taskPosted = true;
265 m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerF ired,
266 m_weakFactory.GetWeakPtr()),
267 uploaderBusyTickRate * 1000);
258 return true; 268 return true;
259 } 269 }
260 270
261 if (!m_queue->fullUploadSize()) 271 if (!m_queue->fullUploadSize())
262 return false; 272 return false;
263 273
264 bool hasTimeRemaining = m_timeLimit.is_null() || 274 bool hasTimeRemaining = m_timeLimit.is_null() ||
265 this->now() < m_timeLimit - updateMoreTexturesTime(); 275 this->now() < m_timeLimit - updateMoreTexturesTime();
266 if (hasTimeRemaining) 276 if (hasTimeRemaining)
267 updateMoreTexturesNow(); 277 updateMoreTexturesNow();
268 278
269 return true; 279 return true;
270 } 280 }
271 281
272 void ResourceUpdateController::updateMoreTexturesNow() 282 void ResourceUpdateController::updateMoreTexturesNow()
273 { 283 {
274 size_t uploads = std::min( 284 size_t uploads = std::min(
275 m_queue->fullUploadSize(), updateMoreTexturesSize()); 285 m_queue->fullUploadSize(), updateMoreTexturesSize());
276 m_timer->startOneShot( 286 m_taskPosted = true;
277 updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() * 287 m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerFired ,
278 uploads); 288 m_weakFactory.GetWeakPtr()),
289 updateMoreTexturesTime().InSecondsF() / updateMore TexturesSize() * uploads * 1000);
279 290
280 if (!uploads) 291 if (!uploads)
281 return; 292 return;
282 293
283 size_t uploadCount = 0; 294 size_t uploadCount = 0;
284 while (m_queue->fullUploadSize() && uploadCount < uploads) { 295 while (m_queue->fullUploadSize() && uploadCount < uploads) {
285 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) 296 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
286 m_resourceProvider->shallowFlushIfSupported(); 297 m_resourceProvider->shallowFlushIfSupported();
287 updateTexture(m_queue->takeFirstFullUpload()); 298 updateTexture(m_queue->takeFirstFullUpload());
288 uploadCount++; 299 uploadCount++;
289 } 300 }
290 m_resourceProvider->shallowFlushIfSupported(); 301 m_resourceProvider->shallowFlushIfSupported();
291 } 302 }
292 303
293 } // namespace cc 304 } // 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