[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 7 | #include "cc/resource_update_controller.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 8 | |
[email protected] | 6331a117 | 2012-10-18 11:35:13 | [diff] [blame] | 9 | #include "base/debug/trace_event.h" |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 10 | #include "cc/prioritized_texture.h" |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 11 | #include "cc/proxy.h" |
[email protected] | c4040a52 | 2012-10-21 15:01:40 | [diff] [blame] | 12 | #include "cc/resource_provider.h" |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 13 | #include "cc/texture_copier.h" |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 14 | #include "cc/thread.h" |
[email protected] | 4456eee2 | 2012-10-19 18:16:38 | [diff] [blame] | 15 | #include "third_party/khronos/GLES2/gl2.h" |
| 16 | #include "third_party/skia/include/gpu/SkGpuDevice.h" |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 17 | #include <limits> |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 18 | #include <public/WebGraphicsContext3D.h> |
| 19 | #include <public/WebSharedGraphicsContext3D.h> |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 20 | |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 21 | using WebKit::WebGraphicsContext3D; |
| 22 | using WebKit::WebSharedGraphicsContext3D; |
| 23 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 24 | namespace { |
| 25 | |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 26 | // Number of partial updates we allow. |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 27 | const size_t partialTextureUpdatesMax = 12; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 28 | |
| 29 | // Measured in seconds. |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 30 | const double textureUpdateTickRate = 0.004; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 31 | |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 32 | // Measured in seconds. |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 33 | const double uploaderBusyTickRate = 0.001; |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 34 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | // Flush interval when performing texture uploads. |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 36 | const int textureUploadFlushPeriod = 4; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 38 | // Number of blocking update intervals to allow. |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 39 | const size_t maxBlockingUpdateIntervals = 4; |
[email protected] | 549526e9 | 2012-09-29 15:43:08 | [diff] [blame] | 40 | |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 41 | scoped_ptr<SkCanvas> createAcceleratedCanvas( |
[email protected] | f809d3bb | 2012-10-31 20:52:25 | [diff] [blame] | 42 | GrContext* grContext, gfx::Size canvasSize, unsigned textureId) |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 43 | { |
| 44 | GrPlatformTextureDesc textureDesc; |
| 45 | textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag; |
| 46 | textureDesc.fWidth = canvasSize.width(); |
| 47 | textureDesc.fHeight = canvasSize.height(); |
| 48 | textureDesc.fConfig = kSkia8888_GrPixelConfig; |
| 49 | textureDesc.fTextureHandle = textureId; |
| 50 | SkAutoTUnref<GrTexture> target( |
| 51 | grContext->createPlatformTexture(textureDesc)); |
| 52 | SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get())); |
| 53 | return make_scoped_ptr(new SkCanvas(device.get())); |
| 54 | } |
| 55 | |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 56 | } // namespace |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 57 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 58 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 59 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 60 | size_t ResourceUpdateController::maxPartialTextureUpdates() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 61 | { |
[email protected] | a7c078b | 2012-09-20 17:52:12 | [diff] [blame] | 62 | return partialTextureUpdatesMax; |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 65 | size_t ResourceUpdateController::maxFullUpdatesPerTick( |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 66 | ResourceProvider* resourceProvider) |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 67 | { |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 68 | double texturesPerSecond = resourceProvider->estimatedUploadsPerSecond(); |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 69 | size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); |
| 70 | return texturesPerTick ? texturesPerTick : 1; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 73 | ResourceUpdateController::ResourceUpdateController(ResourceUpdateControllerClient* client, Thread* thread, scoped_ptr<ResourceUpdateQueue> queue, ResourceProvider* resourceProvider) |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 74 | : m_client(client) |
[email protected] | b1b800c | 2012-10-16 05:03:59 | [diff] [blame] | 75 | , m_queue(queue.Pass()) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 76 | , m_resourceProvider(resourceProvider) |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 77 | , m_textureUpdatesPerTick(maxFullUpdatesPerTick(resourceProvider)) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 78 | , m_firstUpdateAttempt(true) |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 79 | , m_thread(thread) |
| 80 | , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) |
| 81 | , m_taskPosted(false) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 85 | ResourceUpdateController::~ResourceUpdateController() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 86 | { |
| 87 | } |
| 88 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 89 | void ResourceUpdateController::performMoreUpdates( |
[email protected] | d918afe | 2012-09-27 19:27:21 | [diff] [blame] | 90 | base::TimeTicks timeLimit) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 91 | { |
[email protected] | d918afe | 2012-09-27 19:27:21 | [diff] [blame] | 92 | m_timeLimit = timeLimit; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 93 | |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 94 | // Update already in progress. |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 95 | if (m_taskPosted) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 96 | return; |
| 97 | |
| 98 | // Call updateMoreTexturesNow() directly unless it's the first update |
| 99 | // attempt. This ensures that we empty the update queue in a finite |
| 100 | // amount of time. |
| 101 | if (m_firstUpdateAttempt) { |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 102 | // Post a 0-delay task when no updates were left. When it runs, |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 103 | // readyToFinalizeTextureUpdates() will be called. |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 104 | if (!updateMoreTexturesIfEnoughTimeRemaining()) { |
| 105 | m_taskPosted = true; |
| 106 | m_thread->postTask(base::Bind(&ResourceUpdateController::onTimerFired, |
| 107 | m_weakFactory.GetWeakPtr())); |
| 108 | } |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 109 | |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | m_firstUpdateAttempt = false; |
| 111 | } else |
| 112 | updateMoreTexturesNow(); |
| 113 | } |
| 114 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 115 | void ResourceUpdateController::discardUploadsToEvictedResources() |
[email protected] | 77a60b9b | 2012-09-19 23:59:01 | [diff] [blame] | 116 | { |
| 117 | m_queue->clearUploadsToEvictedResources(); |
| 118 | } |
| 119 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 120 | void ResourceUpdateController::updateTexture(ResourceUpdate update) |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 121 | { |
| 122 | if (update.picture) { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 123 | PrioritizedTexture* texture = update.texture; |
[email protected] | f809d3bb | 2012-10-31 20:52:25 | [diff] [blame] | 124 | gfx::Rect pictureRect = update.content_rect; |
| 125 | gfx::Rect sourceRect = update.source_rect; |
| 126 | gfx::Vector2d destOffset = update.dest_offset; |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 127 | |
| 128 | texture->acquireBackingTexture(m_resourceProvider); |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 129 | DCHECK(texture->haveBackingTexture()); |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 130 | |
[email protected] | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 131 | DCHECK(m_resourceProvider->resourceType(texture->resourceId()) == |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 132 | ResourceProvider::GLTexture); |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 133 | |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 134 | WebGraphicsContext3D* paintContext = Proxy::hasImplThread() ? |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 135 | WebSharedGraphicsContext3D::compositorThreadContext() : |
| 136 | WebSharedGraphicsContext3D::mainThreadContext(); |
[email protected] | 5bc29a2 | 2012-11-01 21:21:59 | [diff] [blame] | 137 | GrContext* paintGrContext = Proxy::hasImplThread() ? |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 138 | WebSharedGraphicsContext3D::compositorThreadGrContext() : |
| 139 | WebSharedGraphicsContext3D::mainThreadGrContext(); |
| 140 | |
| 141 | // Flush the context in which the backing texture is created so that it |
| 142 | // is available in other shared contexts. It is important to do here |
| 143 | // because the backing texture is created in one context while it is |
| 144 | // being written to in another. |
| 145 | m_resourceProvider->flush(); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 146 | ResourceProvider::ScopedWriteLockGL lock( |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 147 | m_resourceProvider, texture->resourceId()); |
| 148 | |
| 149 | // Make sure ganesh uses the correct GL context. |
| 150 | paintContext->makeContextCurrent(); |
| 151 | |
| 152 | // Create an accelerated canvas to draw on. |
| 153 | scoped_ptr<SkCanvas> canvas = createAcceleratedCanvas( |
| 154 | paintGrContext, texture->size(), lock.textureId()); |
| 155 | |
| 156 | // The compositor expects the textures to be upside-down so it can flip |
| 157 | // the final composited image. Ganesh renders the image upright so we |
| 158 | // need to do a y-flip. |
| 159 | canvas->translate(0.0, texture->size().height()); |
| 160 | canvas->scale(1.0, -1.0); |
| 161 | // Clip to the destination on the texture that must be updated. |
[email protected] | f809d3bb | 2012-10-31 20:52:25 | [diff] [blame] | 162 | canvas->clipRect(SkRect::MakeXYWH(destOffset.x(), |
| 163 | destOffset.y(), |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 164 | sourceRect.width(), |
| 165 | sourceRect.height())); |
| 166 | // Translate the origin of pictureRect to destOffset. |
| 167 | // Note that destOffset is defined relative to sourceRect. |
| 168 | canvas->translate( |
[email protected] | f809d3bb | 2012-10-31 20:52:25 | [diff] [blame] | 169 | pictureRect.x() - sourceRect.x() + destOffset.x(), |
| 170 | pictureRect.y() - sourceRect.y() + destOffset.y()); |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 171 | canvas->drawPicture(*update.picture); |
| 172 | |
| 173 | // Flush ganesh context so that all the rendered stuff appears on the |
| 174 | // texture. |
| 175 | paintGrContext->flush(); |
| 176 | |
| 177 | // Flush the GL context so rendering results from this context are |
| 178 | // visible in the compositor's context. |
| 179 | paintContext->flush(); |
| 180 | } |
| 181 | |
| 182 | if (update.bitmap) { |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 183 | update.bitmap->lockPixels(); |
[email protected] | a3d2445 | 2012-11-02 06:26:24 | [diff] [blame^] | 184 | update.texture->setPixels( |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 185 | m_resourceProvider, |
| 186 | static_cast<const uint8_t*>(update.bitmap->getPixels()), |
| 187 | update.content_rect, |
| 188 | update.source_rect, |
| 189 | update.dest_offset); |
| 190 | update.bitmap->unlockPixels(); |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 194 | void ResourceUpdateController::finalize() |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 195 | { |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 196 | size_t uploadCount = 0; |
| 197 | while (m_queue->fullUploadSize()) { |
| 198 | if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 199 | m_resourceProvider->shallowFlushIfSupported(); |
| 200 | |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 201 | updateTexture(m_queue->takeFirstFullUpload()); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 202 | uploadCount++; |
| 203 | } |
| 204 | |
| 205 | while (m_queue->partialUploadSize()) { |
| 206 | if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 207 | m_resourceProvider->shallowFlushIfSupported(); |
| 208 | |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 209 | updateTexture(m_queue->takeFirstPartialUpload()); |
[email protected] | f961b79 | 2012-09-20 07:27:33 | [diff] [blame] | 210 | uploadCount++; |
| 211 | } |
| 212 | |
| 213 | if (uploadCount) |
| 214 | m_resourceProvider->shallowFlushIfSupported(); |
| 215 | |
| 216 | if (m_queue->copySize()) { |
| 217 | TextureCopier* copier = m_resourceProvider->textureCopier(); |
| 218 | while (m_queue->copySize()) |
| 219 | copier->copyTexture(m_queue->takeFirstCopy()); |
| 220 | |
| 221 | // If we've performed any texture copies, we need to insert a flush |
| 222 | // here into the compositor context before letting the main thread |
| 223 | // proceed as it may make draw calls to the source texture of one of |
| 224 | // our copy operations. |
| 225 | copier->flush(); |
| 226 | } |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 229 | void ResourceUpdateController::onTimerFired() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 230 | { |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 231 | m_taskPosted = false; |
[email protected] | 1795308 | 2012-10-24 20:13:32 | [diff] [blame] | 232 | ResourceProvider::debugNotifyEnterZone(0xB000000); |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 233 | if (!updateMoreTexturesIfEnoughTimeRemaining()) |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 234 | m_client->readyToFinalizeTextureUpdates(); |
[email protected] | 1795308 | 2012-10-24 20:13:32 | [diff] [blame] | 235 | ResourceProvider::debugNotifyLeaveZone(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 238 | base::TimeTicks ResourceUpdateController::now() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | { |
[email protected] | d918afe | 2012-09-27 19:27:21 | [diff] [blame] | 240 | return base::TimeTicks::Now(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 241 | } |
| 242 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 243 | base::TimeDelta ResourceUpdateController::updateMoreTexturesTime() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 244 | { |
[email protected] | d918afe | 2012-09-27 19:27:21 | [diff] [blame] | 245 | return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 246 | } |
| 247 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 248 | size_t ResourceUpdateController::updateMoreTexturesSize() const |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 249 | { |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 250 | return m_textureUpdatesPerTick; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 253 | size_t ResourceUpdateController::maxBlockingUpdates() const |
[email protected] | 549526e9 | 2012-09-29 15:43:08 | [diff] [blame] | 254 | { |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 255 | return updateMoreTexturesSize() * maxBlockingUpdateIntervals; |
[email protected] | 549526e9 | 2012-09-29 15:43:08 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 258 | bool ResourceUpdateController::updateMoreTexturesIfEnoughTimeRemaining() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 259 | { |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 260 | // Blocking uploads will increase when we're too aggressive in our upload |
[email protected] | 549526e9 | 2012-09-29 15:43:08 | [diff] [blame] | 261 | // time estimate. We use a different timeout here to prevent unnecessary |
[email protected] | b914e10 | 2012-10-02 08:11:52 | [diff] [blame] | 262 | // amounts of idle time when blocking uploads have reached the max. |
[email protected] | e224959 | 2012-10-19 06:59:09 | [diff] [blame] | 263 | if (m_resourceProvider->numBlockingUploads() >= maxBlockingUpdates()) { |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 264 | m_taskPosted = true; |
| 265 | m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerFired, |
| 266 | m_weakFactory.GetWeakPtr()), |
| 267 | uploaderBusyTickRate * 1000); |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 268 | return true; |
| 269 | } |
| 270 | |
| 271 | if (!m_queue->fullUploadSize()) |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 272 | return false; |
| 273 | |
[email protected] | e8e410d | 2012-09-28 01:47:01 | [diff] [blame] | 274 | bool hasTimeRemaining = m_timeLimit.is_null() || |
| 275 | this->now() < m_timeLimit - updateMoreTexturesTime(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 276 | if (hasTimeRemaining) |
| 277 | updateMoreTexturesNow(); |
[email protected] | 3c496dc | 2012-09-13 23:14:20 | [diff] [blame] | 278 | |
| 279 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 280 | } |
| 281 | |
[email protected] | b4da203 | 2012-10-25 21:22:55 | [diff] [blame] | 282 | void ResourceUpdateController::updateMoreTexturesNow() |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 283 | { |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 284 | size_t uploads = std::min( |
| 285 | m_queue->fullUploadSize(), updateMoreTexturesSize()); |
[email protected] | 4a048891 | 2012-10-30 23:29:50 | [diff] [blame] | 286 | m_taskPosted = true; |
| 287 | m_thread->postDelayedTask(base::Bind(&ResourceUpdateController::onTimerFired, |
| 288 | m_weakFactory.GetWeakPtr()), |
| 289 | updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() * uploads * 1000); |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 290 | |
| 291 | if (!uploads) |
| 292 | return; |
| 293 | |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 294 | size_t uploadCount = 0; |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 295 | while (m_queue->fullUploadSize() && uploadCount < uploads) { |
| 296 | if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 297 | m_resourceProvider->shallowFlushIfSupported(); |
[email protected] | 1e5b6bf5 | 2012-10-18 01:44:52 | [diff] [blame] | 298 | updateTexture(m_queue->takeFirstFullUpload()); |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 299 | uploadCount++; |
[email protected] | 1269515 | 2012-09-17 22:28:14 | [diff] [blame] | 300 | } |
[email protected] | 41b8f68 | 2012-09-19 01:51:17 | [diff] [blame] | 301 | m_resourceProvider->shallowFlushIfSupported(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | 2d86b92 | 2012-10-13 16:57:47 | [diff] [blame] | 304 | } // namespace cc |