Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "CCTextureUpdateController.h" | 7 #include "CCTextureUpdateController.h" |
| 8 | 8 |
| 9 #include "GraphicsContext3D.h" | 9 #include "GraphicsContext3D.h" |
| 10 #include "TextureCopier.h" | 10 #include "TextureCopier.h" |
| 11 #include "TextureUploader.h" | 11 #include "TextureUploader.h" |
| 12 #include "TraceEvent.h" | |
| 13 #include <limits> | |
| 12 #include <wtf/CurrentTime.h> | 14 #include <wtf/CurrentTime.h> |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // Number of textures to update with each call to updateMoreTexturesIfEnoughTime Remaining(). | 18 // Number of partial updates we allow. |
| 17 static const size_t textureUpdatesPerTick = 12; | 19 static const size_t maxPartialTextures = 12; |
|
reveman
2012/09/18 20:34:18
maybe partialTextureUpdatesCount or partialTexture
brianderson
2012/09/18 21:09:31
Going with partialTextureUpdatesMax.
| |
| 18 | 20 |
| 19 // Measured in seconds. | 21 // Measured in seconds. |
| 20 static const double textureUpdateTickRate = 0.004; | 22 static const double textureUpdateTickRate = 0.004; |
| 21 | 23 |
| 22 // Measured in seconds. | 24 // Measured in seconds. |
| 23 static const double uploaderBusyTickRate = 0.001; | 25 static const double uploaderBusyTickRate = 0.001; |
| 24 | 26 |
| 25 // Flush interval when performing texture uploads. | 27 // Flush interval when performing texture uploads. |
| 26 static const int textureUploadFlushPeriod = 4; | 28 static const int textureUploadFlushPeriod = 4; |
| 27 | 29 |
| 28 } // anonymous namespace | 30 } // anonymous namespace |
| 29 | 31 |
| 30 namespace cc { | 32 namespace cc { |
| 31 | 33 |
| 32 size_t CCTextureUpdateController::maxPartialTextureUpdates() | 34 size_t CCTextureUpdateController::maxPartialTextureUpdates() |
| 33 { | 35 { |
| 34 return textureUpdatesPerTick; | 36 return maxPartialTextures; |
| 37 } | |
| 38 | |
| 39 size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploade r) | |
| 40 { | |
| 41 double texturesPerSecond = uploader->estimatedTexturesPerSecond(); | |
| 42 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); | |
| 43 return std::max(static_cast<size_t>(1), texturesPerTick); | |
|
reveman
2012/09/18 20:34:18
you can get rid of the static_cast now, right?
brianderson
2012/09/18 21:09:31
There's a compile error without the static_cast, s
jamesr
2012/09/18 21:13:00
is "1u" as the first parameter enough to escape th
brianderson
2012/09/18 21:15:14
Nope, but 1LU is.
| |
| 35 } | 44 } |
| 36 | 45 |
| 37 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureUploader* uploader, CCTextureUpdateQueue* queue) | 46 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureUploader* uploader, CCTextureUpdateQueue* queue) |
| 38 { | 47 { |
| 39 size_t uploadCount = 0; | 48 size_t uploadCount = 0; |
| 40 while (queue->fullUploadSize()) { | 49 while (queue->fullUploadSize()) { |
| 41 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) | 50 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 42 resourceProvider->shallowFlushIfSupported(); | 51 resourceProvider->shallowFlushIfSupported(); |
| 43 | 52 |
| 44 uploader->uploadTexture( | 53 uploader->uploadTexture( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 71 } | 80 } |
| 72 } | 81 } |
| 73 | 82 |
| 74 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureUploader* uploader) | 83 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureUploader* uploader) |
| 75 : m_client(client) | 84 : m_client(client) |
| 76 , m_timer(adoptPtr(new CCTimer(thread, this))) | 85 , m_timer(adoptPtr(new CCTimer(thread, this))) |
| 77 , m_queue(queue) | 86 , m_queue(queue) |
| 78 , m_resourceProvider(resourceProvider) | 87 , m_resourceProvider(resourceProvider) |
| 79 , m_uploader(uploader) | 88 , m_uploader(uploader) |
| 80 , m_monotonicTimeLimit(0) | 89 , m_monotonicTimeLimit(0) |
| 90 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader)) | |
| 81 , m_firstUpdateAttempt(true) | 91 , m_firstUpdateAttempt(true) |
| 82 { | 92 { |
| 83 } | 93 } |
| 84 | 94 |
| 85 CCTextureUpdateController::~CCTextureUpdateController() | 95 CCTextureUpdateController::~CCTextureUpdateController() |
| 86 { | 96 { |
| 87 } | 97 } |
| 88 | 98 |
| 89 void CCTextureUpdateController::performMoreUpdates( | 99 void CCTextureUpdateController::performMoreUpdates( |
| 90 double monotonicTimeLimit) | 100 double monotonicTimeLimit) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 return monotonicallyIncreasingTime(); | 136 return monotonicallyIncreasingTime(); |
| 127 } | 137 } |
| 128 | 138 |
| 129 double CCTextureUpdateController::updateMoreTexturesTime() const | 139 double CCTextureUpdateController::updateMoreTexturesTime() const |
| 130 { | 140 { |
| 131 return textureUpdateTickRate; | 141 return textureUpdateTickRate; |
| 132 } | 142 } |
| 133 | 143 |
| 134 size_t CCTextureUpdateController::updateMoreTexturesSize() const | 144 size_t CCTextureUpdateController::updateMoreTexturesSize() const |
| 135 { | 145 { |
| 136 return textureUpdatesPerTick; | 146 return m_textureUpdatesPerTick; |
| 137 } | 147 } |
| 138 | 148 |
| 139 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() | 149 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() |
| 140 { | 150 { |
| 141 // Uploader might be busy when we're too aggressive in our upload time | 151 // Uploader might be busy when we're too aggressive in our upload time |
| 142 // estimate. We use a different timeout here to prevent unnecessary | 152 // estimate. We use a different timeout here to prevent unnecessary |
| 143 // amounts of idle time. | 153 // amounts of idle time. |
| 144 if (m_uploader->isBusy()) { | 154 if (m_uploader->isBusy()) { |
| 145 m_timer->startOneShot(uploaderBusyTickRate); | 155 m_timer->startOneShot(uploaderBusyTickRate); |
| 146 return true; | 156 return true; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 159 void CCTextureUpdateController::updateMoreTexturesNow() | 169 void CCTextureUpdateController::updateMoreTexturesNow() |
| 160 { | 170 { |
| 161 size_t uploads = std::min( | 171 size_t uploads = std::min( |
| 162 m_queue->fullUploadSize(), updateMoreTexturesSize()); | 172 m_queue->fullUploadSize(), updateMoreTexturesSize()); |
| 163 m_timer->startOneShot( | 173 m_timer->startOneShot( |
| 164 updateMoreTexturesTime() / updateMoreTexturesSize() * uploads); | 174 updateMoreTexturesTime() / updateMoreTexturesSize() * uploads); |
| 165 | 175 |
| 166 if (!uploads) | 176 if (!uploads) |
| 167 return; | 177 return; |
| 168 | 178 |
| 179 size_t uploadCount = 0; | |
| 169 m_uploader->beginUploads(); | 180 m_uploader->beginUploads(); |
| 170 | 181 while (m_queue->fullUploadSize() && uploadCount < uploads) { |
| 171 size_t uploadCount = 0; | 182 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 172 while (uploads--) { | 183 m_resourceProvider->shallowFlushIfSupported(); |
| 173 m_uploader->uploadTexture( | 184 m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUplo ad()); |
| 174 m_resourceProvider, m_queue->takeFirstFullUpload()); | |
| 175 uploadCount++; | 185 uploadCount++; |
| 176 if (!(uploadCount % textureUploadFlushPeriod)) | |
| 177 m_resourceProvider->shallowFlushIfSupported(); | |
| 178 } | 186 } |
| 179 | |
| 180 // Make sure there are no dangling partial uploads without a flush. | |
| 181 if (uploadCount % textureUploadFlushPeriod) | |
| 182 m_resourceProvider->shallowFlushIfSupported(); | |
| 183 | |
| 184 m_uploader->endUploads(); | 187 m_uploader->endUploads(); |
| 188 m_resourceProvider->shallowFlushIfSupported(); | |
| 185 } | 189 } |
| 186 | 190 |
| 187 } | 191 } |
| OLD | NEW |