Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4468)

Unified Diff: cc/CCTextureUpdateController.cpp

Issue 10916292: Adaptively throttle texture uploads (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Do not vary partial upload limit Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/CCTextureUpdateController.cpp
diff --git a/cc/CCTextureUpdateController.cpp b/cc/CCTextureUpdateController.cpp
index 22207de75f9adf58e4094922578427d865dc25e6..7e680124b5b69dae3858418bb15963dd0c700a1b 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;
reveman 2012/09/18 05:30:35 We could get rid of this awkward constant if parti
brianderson 2012/09/18 20:03:00 Done.
+
+// Minimum number of textures to update with each call to updateMoreTexturesIfEnoughTimeRemaining().
+static const size_t textureUpdatesPerFullTickMin = 12;
nduca 2012/09/18 03:17:06 i think this goes as low as 3 on android... though
reveman 2012/09/18 05:30:35 We should be able to just remove this now that par
brianderson 2012/09/18 20:03:00 I'd like to get rid of it too.
// Measured in seconds.
static const double textureUpdateTickRate = 0.004;
@@ -31,11 +35,20 @@ namespace cc {
size_t CCTextureUpdateController::maxPartialTextureUpdates()
{
- return textureUpdatesPerTick;
+ return textureUpdatesPerFullTickMin;
+}
+
+size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploader)
+{
+ double texturesPerSecond = uploader->estimatedPixelsPerSecond() / pixelsPerTexture;
+
+ return std::max(textureUpdatesPerFullTickMin,
+ (size_t) floor(textureUpdateTickRate * texturesPerSecond));
reveman 2012/09/18 05:30:35 Use static_cast here instead of c-style cast.
brianderson 2012/09/18 20:03:00 Done.
}
void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* queue, size_t count)
{
+ TRACE_EVENT0("cc", "CCTextureUpdateController::updateTextures");
reveman 2012/09/18 05:30:35 You wouldn't have to touch this function at all if
brianderson 2012/09/18 20:03:00 Done.
if (queue->fullUploadSize() || queue->partialUploadSize()) {
if (uploader->isBusy())
return;
@@ -43,43 +56,38 @@ void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi
uploader->beginUploads();
size_t fullUploadCount = 0;
- while (queue->fullUploadSize() && fullUploadCount < count) {
- uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload());
- fullUploadCount++;
- if (!(fullUploadCount % textureUploadFlushPeriod))
+ if (queue->fullUploadSize()) {
+ while (queue->fullUploadSize() && fullUploadCount < count) {
+ if (!(fullUploadCount % textureUploadFlushPeriod) && fullUploadCount)
+ resourceProvider->shallowFlushIfSupported();
+ uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload());
+ fullUploadCount++;
+ }
+
+ bool cantUpdloadAllPartials = (count - fullUploadCount) < queue->partialUploadSize();
reveman 2012/09/18 05:30:35 nit: spelling
+ if (cantUpdloadAllPartials) {
reveman 2012/09/18 05:30:35 here too
+ uploader->endUploads();
resourceProvider->shallowFlushIfSupported();
+ return;
+ }
}
- // 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) {
- uploader->endUploads();
- return;
- }
+ ASSERT(queue->partialUploadSize() <= (count - fullUploadCount));
size_t partialUploadCount = 0;
- while (queue->partialUploadSize()) {
- uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpload());
- partialUploadCount++;
- if (!(partialUploadCount % textureUploadFlushPeriod))
+ if (queue->partialUploadSize()) {
+ if (fullUploadCount)
resourceProvider->shallowFlushIfSupported();
+ while (queue->partialUploadSize()) {
+ if (!(partialUploadCount % textureUploadFlushPeriod) && partialUploadCount)
+ resourceProvider->shallowFlushIfSupported();
+ uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpload());
+ partialUploadCount++;
+ }
}
- // Make sure there are no dangling partial uploads without a flush.
- if (partialUploadCount % textureUploadFlushPeriod)
- resourceProvider->shallowFlushIfSupported();
-
uploader->endUploads();
+ resourceProvider->shallowFlushIfSupported();
}
size_t copyCount = 0;
@@ -103,6 +111,7 @@ CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl
, m_copier(copier)
, m_uploader(uploader)
, m_monotonicTimeLimit(0)
+ , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader))
, m_firstUpdateAttempt(true)
{
}
@@ -160,7 +169,7 @@ double CCTextureUpdateController::updateMoreTexturesTime() const
size_t CCTextureUpdateController::updateMoreTexturesSize() const
{
- return textureUpdatesPerTick;
+ return m_textureUpdatesPerTick;
}
bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
@@ -193,22 +202,16 @@ void CCTextureUpdateController::updateMoreTexturesNow()
if (!uploads)
return;
+ size_t fullUploadCount = 0;
m_uploader->beginUploads();
-
- size_t uploadCount = 0;
- while (uploads--) {
- m_uploader->uploadTexture(
- m_resourceProvider, m_queue->takeFirstFullUpload());
- uploadCount++;
- if (!(uploadCount % textureUploadFlushPeriod))
+ while (m_queue->fullUploadSize() && fullUploadCount < uploads) {
+ if (!(fullUploadCount % textureUploadFlushPeriod) && fullUploadCount)
m_resourceProvider->shallowFlushIfSupported();
+ m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUpload());
+ fullUploadCount++;
}
-
- // Make sure there are no dangling partial uploads without a flush.
- if (uploadCount % textureUploadFlushPeriod)
- m_resourceProvider->shallowFlushIfSupported();
-
m_uploader->endUploads();
+ m_resourceProvider->shallowFlushIfSupported();
}
}

Powered by Google App Engine
This is Rietveld 408576698