| Index: cc/CCTextureUpdateController.cpp
|
| diff --git a/cc/CCTextureUpdateController.cpp b/cc/CCTextureUpdateController.cpp
|
| index 25d41cca581bb25b83adb03ad0fbf5172fee4c23..faba8e2778add246d09362d7407606ff118a5283 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,17 @@ static const int textureUploadFlushPeriod = 4;
|
|
|
| namespace WebCore {
|
|
|
| -size_t CCTextureUpdateController::maxPartialTextureUpdates()
|
| +size_t CCTextureUpdateController::maxTextureUpdates(TextureUploader* uploader)
|
| {
|
| - return textureUpdatesPerTick;
|
| + 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 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 +52,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;
|
| +
|
| + // Flush periodically, but deffer 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 deffer 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 +101,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)
|
| {
|
| }
|
| @@ -127,6 +137,7 @@ void CCTextureUpdateController::updateMoreTextures(double monotonicTimeLimit)
|
| m_firstUpdateAttempt = false;
|
| } else
|
| updateMoreTexturesNow();
|
| +
|
| }
|
|
|
| void CCTextureUpdateController::onTimerFired()
|
| @@ -149,7 +160,7 @@ double CCTextureUpdateController::updateMoreTexturesTime() const
|
|
|
| size_t CCTextureUpdateController::updateMoreTexturesSize() const
|
| {
|
| - return textureUpdatesPerTick;
|
| + return m_textureUpdatesPerTick;
|
| }
|
|
|
| void CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
|
|
|