Chromium Code Reviews| Index: cc/CCTextureUpdateController.cpp |
| diff --git a/cc/CCTextureUpdateController.cpp b/cc/CCTextureUpdateController.cpp |
| index 25d41cca581bb25b83adb03ad0fbf5172fee4c23..6c67dfebaeccc17d4db298b7976c91a24b674416 100644 |
| --- a/cc/CCTextureUpdateController.cpp |
| +++ b/cc/CCTextureUpdateController.cpp |
| @@ -9,12 +9,16 @@ |
| #include "GraphicsContext3D.h" |
| #include "TextureCopier.h" |
| #include "TextureUploader.h" |
| +#include "TraceEvent.h" |
| +#include <limits> |
| #include <wtf/CurrentTime.h> |
| namespace { |
| -// Number of textures to update with each call to updateMoreTexturesIfEnoughTimeRemaining(). |
| -static const size_t textureUpdatesPerTick = 12; |
| +static const size_t pixelsPerTexture = 256 * 256; |
| + |
| +// Minimum number of textures to update with each call to updateMoreTexturesIfEnoughTimeRemaining(). |
| +static const size_t textureUpdatesPerFullTickMin = 12; |
| // Measured in seconds. |
| static const double textureUpdateTickRate = 0.004; |
| @@ -26,9 +30,22 @@ static const int textureUploadFlushPeriod = 4; |
| namespace WebCore { |
| -size_t CCTextureUpdateController::maxPartialTextureUpdates() |
| +size_t CCTextureUpdateController::maxTextureUpdatesDefault() |
| +{ |
| + return textureUpdatesPerFullTickMin; |
| +} |
| + |
| +size_t CCTextureUpdateController::maxTextureUpdates(TextureUploader* uploader) |
| +{ |
| + double texturesPerSecond = uploader->estimatedPixelsPerSecond() / pixelsPerTexture; |
| + |
| + return std::max(textureUpdatesPerFullTickMin, |
| + (size_t) floor(textureUpdateTickRate * texturesPerSecond)); |
| +} |
| + |
| +PassOwnPtr<CCTextureUpdateController> CCTextureUpdateController::create(CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader, size_t maxTextureUpdates) |
| { |
| - return textureUpdatesPerTick; |
| + return adoptPtr(new CCTextureUpdateController(thread, queue, resourceProvider, copier, uploader, maxTextureUpdates)); |
| } |
| void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* queue, size_t count) |
| @@ -40,43 +57,40 @@ void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi |
| uploader->beginUploads(); |
| size_t fullUploadCount = 0; |
| - while (queue->fullUploadSize() && fullUploadCount < count) { |
| + bool uploadMore = queue->fullUploadSize() && fullUploadCount < count; |
| + while (uploadMore) { |
| uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload()); |
| fullUploadCount++; |
| - if (!(fullUploadCount % textureUploadFlushPeriod)) |
| + uploadMore = queue->fullUploadSize() && fullUploadCount < count; |
|
reveman
2012/09/15 17:26:19
hm, I feel like this has grown into something that
brianderson
2012/09/17 22:48:27
Sounds good. I was able to make it shorter and mor
|
| + |
| + // Flush periodically, but defer our last flush until after uploader->endUploads() |
| + // in order to keep the query associated with endUploads grouped with our last texture upload. |
| + if (!(fullUploadCount % textureUploadFlushPeriod) && uploadMore) |
| resourceProvider->shallowFlushIfSupported(); |
| } |
| - // Make sure there are no dangling uploads without a flush. |
| - if (fullUploadCount % textureUploadFlushPeriod) |
| - resourceProvider->shallowFlushIfSupported(); |
| - |
| - bool moreUploads = queue->fullUploadSize(); |
| - |
| ASSERT(queue->partialUploadSize() <= count); |
| - // We need another update batch if the number of updates remaining |
| - // in |count| is greater than the remaining partial entries. |
| - if ((count - fullUploadCount) < queue->partialUploadSize()) |
| - moreUploads = true; |
| - |
| - if (moreUploads) { |
| + bool needAnotherTick = queue->fullUploadSize() || ((count - fullUploadCount) < queue->partialUploadSize()); |
| + if (needAnotherTick) { |
| uploader->endUploads(); |
| + resourceProvider->shallowFlushIfSupported(); |
| return; |
| } |
| + resourceProvider->shallowFlushIfSupported(); |
| size_t partialUploadCount = 0; |
| while (queue->partialUploadSize()) { |
| uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpload()); |
| partialUploadCount++; |
| - if (!(partialUploadCount % textureUploadFlushPeriod)) |
| + |
| + // Flush periodically, but defer our last flush until after uploader->endUploads() |
| + // in order to keep the query associated with endUploads grouped with our last texture upload. |
| + if (!(partialUploadCount % textureUploadFlushPeriod) && queue->partialUploadSize()) |
| resourceProvider->shallowFlushIfSupported(); |
| } |
| - // Make sure there are no dangling partial uploads without a flush. |
| - if (partialUploadCount % textureUploadFlushPeriod) |
| - resourceProvider->shallowFlushIfSupported(); |
| - |
| uploader->endUploads(); |
| + resourceProvider->shallowFlushIfSupported(); |
| } |
| size_t copyCount = 0; |
| @@ -92,13 +106,14 @@ void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi |
| copier->flush(); |
| } |
| -CCTextureUpdateController::CCTextureUpdateController(CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) |
| +CCTextureUpdateController::CCTextureUpdateController(CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader, size_t maxTextureUpdates) |
| : m_timer(adoptPtr(new CCTimer(thread, this))) |
| , m_queue(queue) |
| , m_resourceProvider(resourceProvider) |
| , m_copier(copier) |
| , m_uploader(uploader) |
| , m_monotonicTimeLimit(0) |
| + , m_textureUpdatesPerTick(maxTextureUpdates) |
| , m_firstUpdateAttempt(true) |
| { |
| } |
| @@ -149,7 +164,7 @@ double CCTextureUpdateController::updateMoreTexturesTime() const |
| size_t CCTextureUpdateController::updateMoreTexturesSize() const |
| { |
| - return textureUpdatesPerTick; |
| + return m_textureUpdatesPerTick; |
| } |
| void CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() |