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