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 <wtf/CurrentTime.h> | 12 |
| 13 using namespace std; | |
|
jamesr
2012/09/14 23:03:06
chromium and WebKit style is to prefer std::foo in
reveman
2012/09/14 23:38:00
Hm, I see a lot of the using directive in cc. I th
jamesr
2012/09/17 06:57:38
This changed in WebKit several months ago: http://
reveman
2012/09/17 15:32:52
ok, clear.
| |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Number of textures to update with each call to updateMoreTexturesIfEnoughTime Remaining(). | 17 // Number of textures to update with each call to updateMoreTextures(). |
| 17 static const size_t textureUpdatesPerTick = 12; | 18 static const size_t textureUpdatesPerTick = 12; |
| 18 | 19 |
| 19 // Measured in seconds. | 20 // Measured in seconds. |
| 20 static const double textureUpdateTickRate = 0.004; | 21 static const double textureUpdateTickRate = 0.004; |
| 21 | 22 |
| 23 // Measured in seconds. | |
| 24 static const double uploaderBusyTickRate = 0.001; | |
| 25 | |
| 22 // Flush interval when performing texture uploads. | 26 // Flush interval when performing texture uploads. |
| 23 static const int textureUploadFlushPeriod = 4; | 27 static const int textureUploadFlushPeriod = 4; |
| 24 | 28 |
| 25 } // anonymous namespace | 29 } // anonymous namespace |
| 26 | 30 |
| 27 namespace WebCore { | 31 namespace WebCore { |
| 28 | 32 |
| 29 size_t CCTextureUpdateController::maxPartialTextureUpdates() | 33 size_t CCTextureUpdateController::maxPartialTextureUpdates() |
| 30 { | 34 { |
| 31 return textureUpdatesPerTick; | 35 return textureUpdatesPerTick; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 copier->flush(); | 96 copier->flush(); |
| 93 } | 97 } |
| 94 | 98 |
| 95 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) | 99 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) |
| 96 : m_client(client) | 100 : m_client(client) |
| 97 , m_timer(adoptPtr(new CCTimer(thread, this))) | 101 , m_timer(adoptPtr(new CCTimer(thread, this))) |
| 98 , m_queue(queue) | 102 , m_queue(queue) |
| 99 , m_resourceProvider(resourceProvider) | 103 , m_resourceProvider(resourceProvider) |
| 100 , m_copier(copier) | 104 , m_copier(copier) |
| 101 , m_uploader(uploader) | 105 , m_uploader(uploader) |
| 102 , m_monotonicTimeLimit(0) | |
| 103 , m_firstUpdateAttempt(true) | |
| 104 { | 106 { |
| 105 } | 107 } |
| 106 | 108 |
| 107 CCTextureUpdateController::~CCTextureUpdateController() | 109 CCTextureUpdateController::~CCTextureUpdateController() |
| 108 { | 110 { |
| 109 } | 111 } |
| 110 | 112 |
| 111 void CCTextureUpdateController::updateMoreTextures(double monotonicTimeLimit) | 113 void CCTextureUpdateController::start() |
| 112 { | 114 { |
| 113 ASSERT(monotonicTimeLimit >= m_monotonicTimeLimit); | 115 // Post a 0-delay task when no updates were left. When it runs, |
| 114 m_monotonicTimeLimit = monotonicTimeLimit; | 116 // updateTexturesCompleted() will be called. |
| 117 if (!updateMoreTextures()) | |
| 118 m_timer->startOneShot(0); | |
| 119 } | |
| 115 | 120 |
| 116 // Update already in progress. | 121 void CCTextureUpdateController::updateAllTexturesNow() |
| 117 if (m_timer->isActive()) | 122 { |
| 123 if (!m_queue->hasMoreUpdates()) | |
| 118 return; | 124 return; |
| 119 | 125 |
| 120 // Call updateMoreTexturesNow() directly unless it's the first update | 126 updateTextures( |
| 121 // attempt. This ensures that we empty the update queue in a finite | 127 m_resourceProvider, m_copier, m_uploader, m_queue.get(), |
| 122 // amount of time. | 128 numeric_limits<size_t>::max()); |
| 123 if (m_firstUpdateAttempt) { | |
| 124 // Post a 0-delay task when no updates were left. When it runs, | |
| 125 // updateTexturesCompleted() will be called. | |
| 126 if (!updateMoreTexturesIfEnoughTimeRemaining()) | |
| 127 m_timer->startOneShot(0); | |
| 128 | |
| 129 m_firstUpdateAttempt = false; | |
| 130 } else | |
| 131 updateMoreTexturesNow(); | |
| 132 } | 129 } |
| 133 | 130 |
| 134 void CCTextureUpdateController::onTimerFired() | 131 void CCTextureUpdateController::onTimerFired() |
| 135 { | 132 { |
| 136 if (!updateMoreTexturesIfEnoughTimeRemaining()) | 133 if (!updateMoreTextures()) |
| 137 m_client->updateTexturesCompleted(); | 134 m_client->updateTexturesCompleted(); |
| 138 } | 135 } |
| 139 | 136 |
| 140 double CCTextureUpdateController::monotonicTimeNow() const | |
| 141 { | |
| 142 return monotonicallyIncreasingTime(); | |
| 143 } | |
| 144 | |
| 145 double CCTextureUpdateController::updateMoreTexturesTime() const | 137 double CCTextureUpdateController::updateMoreTexturesTime() const |
| 146 { | 138 { |
| 147 return textureUpdateTickRate; | 139 return textureUpdateTickRate; |
| 148 } | 140 } |
| 149 | 141 |
| 150 size_t CCTextureUpdateController::updateMoreTexturesSize() const | 142 size_t CCTextureUpdateController::updateMoreTexturesSize() const |
| 151 { | 143 { |
| 152 return textureUpdatesPerTick; | 144 return textureUpdatesPerTick; |
| 153 } | 145 } |
| 154 | 146 |
| 155 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() | 147 // Performs buffered texture updates. Currently only full uploads. |
| 148 bool CCTextureUpdateController::updateMoreTextures() | |
| 156 { | 149 { |
| 157 if (!m_queue->hasMoreUpdates()) | 150 if (m_uploader->isBusy()) { |
| 151 m_timer->startOneShot(uploaderBusyTickRate); | |
|
jamesr
2012/09/14 23:03:06
why the new 1ms delay? did anything in the previou
reveman
2012/09/14 23:38:00
So the main reason this code is here is because we
jamesr
2012/09/17 06:57:38
This is all because we poll (via the query object)
reveman
2012/09/17 15:32:52
Yes, it's because we poll.
| |
| 152 return true; | |
| 153 } | |
| 154 | |
| 155 if (!m_queue->fullUploadSize()) | |
| 158 return false; | 156 return false; |
| 159 | 157 |
| 160 bool hasTimeRemaining = monotonicTimeNow() < m_monotonicTimeLimit - updateMo reTexturesTime(); | 158 size_t uploads = min(m_queue->fullUploadSize(), updateMoreTexturesSize()); |
| 161 if (hasTimeRemaining) | 159 m_timer->startOneShot( |
| 162 updateMoreTexturesNow(); | 160 updateMoreTexturesTime() / updateMoreTexturesSize() * uploads); |
| 163 | 161 |
| 162 m_uploader->beginUploads(); | |
| 163 | |
| 164 size_t uploadCount = 0; | |
| 165 while (uploads--) { | |
| 166 m_uploader->uploadTexture( | |
| 167 m_resourceProvider, m_queue->takeFirstFullUpload()); | |
| 168 uploadCount++; | |
| 169 if (!(uploadCount % textureUploadFlushPeriod)) | |
| 170 m_resourceProvider->shallowFlushIfSupported(); | |
| 171 } | |
| 172 | |
| 173 // Make sure there are no dangling partial uploads without a flush. | |
| 174 if (uploadCount % textureUploadFlushPeriod) | |
| 175 m_resourceProvider->shallowFlushIfSupported(); | |
| 176 | |
| 177 m_uploader->endUploads(); | |
| 164 return true; | 178 return true; |
| 165 } | 179 } |
| 166 | 180 |
| 167 void CCTextureUpdateController::updateMoreTexturesNow() | |
| 168 { | |
| 169 m_timer->startOneShot(updateMoreTexturesTime()); | |
| 170 updateTextures(m_resourceProvider, m_copier, m_uploader, m_queue.get(), upda teMoreTexturesSize()); | |
| 171 } | 181 } |
| 172 | |
| 173 } | |
| OLD | NEW |