summaryrefslogtreecommitdiffstats
path: root/cc/texture_update_controller.cc
diff options
context:
space:
mode:
authorenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 22:43:41 +0000
committerenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-12 22:43:41 +0000
commitcd57cc5a246367c2558fefa04ae9eca8f4d545d2 (patch)
treea2235045e9c5e4ff028d641b76f5d01aa5461b26 /cc/texture_update_controller.cc
parent3fe7ba055be580443445895c0ee01ada3b628487 (diff)
downloadchromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.zip
chromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.tar.gz
chromium_src-cd57cc5a246367c2558fefa04ae9eca8f4d545d2.tar.bz2
[cc] Rename all cc/ filenames to Chromium style
BUG=155413 Review URL: https://codereview.chromium.org/11122003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/texture_update_controller.cc')
-rw-r--r--cc/texture_update_controller.cc197
1 files changed, 197 insertions, 0 deletions
diff --git a/cc/texture_update_controller.cc b/cc/texture_update_controller.cc
new file mode 100644
index 0000000..200948d
--- /dev/null
+++ b/cc/texture_update_controller.cc
@@ -0,0 +1,197 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+
+#include "CCTextureUpdateController.h"
+
+#include "GraphicsContext3D.h"
+#include "TextureCopier.h"
+#include "TextureUploader.h"
+#include "TraceEvent.h"
+#include <limits>
+#include <wtf/CurrentTime.h>
+
+namespace {
+
+// Number of partial updates we allow.
+static const size_t partialTextureUpdatesMax = 12;
+
+// Measured in seconds.
+static const double textureUpdateTickRate = 0.004;
+
+// Measured in seconds.
+static const double uploaderBusyTickRate = 0.001;
+
+// Flush interval when performing texture uploads.
+static const int textureUploadFlushPeriod = 4;
+
+// Number of blocking update intervals to allow.
+static const size_t maxBlockingUpdateIntervals = 4;
+
+} // anonymous namespace
+
+namespace cc {
+
+size_t CCTextureUpdateController::maxPartialTextureUpdates()
+{
+ return partialTextureUpdatesMax;
+}
+
+size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploader)
+{
+ double texturesPerSecond = uploader->estimatedTexturesPerSecond();
+ size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond);
+ return texturesPerTick ? texturesPerTick : 1;
+}
+
+CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerClient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureUploader* uploader)
+ : m_client(client)
+ , m_timer(adoptPtr(new CCTimer(thread, this)))
+ , m_queue(queue)
+ , m_resourceProvider(resourceProvider)
+ , m_uploader(uploader)
+ , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader))
+ , m_firstUpdateAttempt(true)
+{
+}
+
+CCTextureUpdateController::~CCTextureUpdateController()
+{
+}
+
+void CCTextureUpdateController::performMoreUpdates(
+ base::TimeTicks timeLimit)
+{
+ m_timeLimit = timeLimit;
+
+ // Update already in progress.
+ if (m_timer->isActive())
+ return;
+
+ // Call updateMoreTexturesNow() directly unless it's the first update
+ // attempt. This ensures that we empty the update queue in a finite
+ // amount of time.
+ if (m_firstUpdateAttempt) {
+ // Post a 0-delay task when no updates were left. When it runs,
+ // readyToFinalizeTextureUpdates() will be called.
+ if (!updateMoreTexturesIfEnoughTimeRemaining())
+ m_timer->startOneShot(0);
+
+ m_firstUpdateAttempt = false;
+ } else
+ updateMoreTexturesNow();
+}
+
+void CCTextureUpdateController::discardUploadsToEvictedResources()
+{
+ m_queue->clearUploadsToEvictedResources();
+}
+
+void CCTextureUpdateController::finalize()
+{
+ size_t uploadCount = 0;
+ while (m_queue->fullUploadSize()) {
+ if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
+ m_resourceProvider->shallowFlushIfSupported();
+
+ m_uploader->uploadTexture(
+ m_resourceProvider, m_queue->takeFirstFullUpload());
+ uploadCount++;
+ }
+
+ while (m_queue->partialUploadSize()) {
+ if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
+ m_resourceProvider->shallowFlushIfSupported();
+
+ m_uploader->uploadTexture(
+ m_resourceProvider, m_queue->takeFirstPartialUpload());
+ uploadCount++;
+ }
+
+ if (uploadCount)
+ m_resourceProvider->shallowFlushIfSupported();
+
+ if (m_queue->copySize()) {
+ TextureCopier* copier = m_resourceProvider->textureCopier();
+ while (m_queue->copySize())
+ copier->copyTexture(m_queue->takeFirstCopy());
+
+ // If we've performed any texture copies, we need to insert a flush
+ // here into the compositor context before letting the main thread
+ // proceed as it may make draw calls to the source texture of one of
+ // our copy operations.
+ copier->flush();
+ }
+}
+
+void CCTextureUpdateController::onTimerFired()
+{
+ if (!updateMoreTexturesIfEnoughTimeRemaining())
+ m_client->readyToFinalizeTextureUpdates();
+}
+
+base::TimeTicks CCTextureUpdateController::now() const
+{
+ return base::TimeTicks::Now();
+}
+
+base::TimeDelta CCTextureUpdateController::updateMoreTexturesTime() const
+{
+ return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000);
+}
+
+size_t CCTextureUpdateController::updateMoreTexturesSize() const
+{
+ return m_textureUpdatesPerTick;
+}
+
+size_t CCTextureUpdateController::maxBlockingUpdates() const
+{
+ return updateMoreTexturesSize() * maxBlockingUpdateIntervals;
+}
+
+bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
+{
+ // Blocking uploads will increase when we're too aggressive in our upload
+ // time estimate. We use a different timeout here to prevent unnecessary
+ // amounts of idle time when blocking uploads have reached the max.
+ if (m_uploader->numBlockingUploads() >= maxBlockingUpdates()) {
+ m_timer->startOneShot(uploaderBusyTickRate);
+ return true;
+ }
+
+ if (!m_queue->fullUploadSize())
+ return false;
+
+ bool hasTimeRemaining = m_timeLimit.is_null() ||
+ this->now() < m_timeLimit - updateMoreTexturesTime();
+ if (hasTimeRemaining)
+ updateMoreTexturesNow();
+
+ return true;
+}
+
+void CCTextureUpdateController::updateMoreTexturesNow()
+{
+ size_t uploads = std::min(
+ m_queue->fullUploadSize(), updateMoreTexturesSize());
+ m_timer->startOneShot(
+ updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() *
+ uploads);
+
+ if (!uploads)
+ return;
+
+ size_t uploadCount = 0;
+ while (m_queue->fullUploadSize() && uploadCount < uploads) {
+ if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
+ m_resourceProvider->shallowFlushIfSupported();
+ m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUpload());
+ uploadCount++;
+ }
+ m_resourceProvider->shallowFlushIfSupported();
+}
+
+}