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 "TraceEvent.h" | |
| 13 #include <limits> | |
| 12 #include <wtf/CurrentTime.h> | 14 #include <wtf/CurrentTime.h> |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // Number of textures to update with each call to updateMoreTexturesIfEnoughTime Remaining(). | 18 static const size_t pixelsPerTexture = 256 * 256; |
| 17 static const size_t textureUpdatesPerTick = 12; | 19 |
| 20 // Minimum number of textures to update with each call to updateMoreTexturesIfEn oughTimeRemaining(). | |
| 21 static const size_t textureUpdatesPerFullTickMin = 12; | |
| 18 | 22 |
| 19 // Measured in seconds. | 23 // Measured in seconds. |
| 20 static const double textureUpdateTickRate = 0.004; | 24 static const double textureUpdateTickRate = 0.004; |
| 21 | 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::maxTextureUpdatesDefault() |
| 30 { | 34 { |
| 31 return textureUpdatesPerTick; | 35 return textureUpdatesPerFullTickMin; |
| 36 } | |
| 37 | |
| 38 size_t CCTextureUpdateController::maxTextureUpdates(TextureUploader* uploader) | |
| 39 { | |
| 40 double texturesPerSecond = uploader->estimatedPixelsPerSecond() / pixelsPerT exture; | |
| 41 | |
| 42 return std::max(textureUpdatesPerFullTickMin, | |
| 43 (size_t) floor(textureUpdateTickRate * texturesPerSecond)); | |
| 44 } | |
| 45 | |
| 46 PassOwnPtr<CCTextureUpdateController> CCTextureUpdateController::create(CCThread * thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResourceProvider* resourcePr ovider, TextureCopier* copier, TextureUploader* uploader, size_t maxTextureUpdat es) | |
| 47 { | |
| 48 return adoptPtr(new CCTextureUpdateController(thread, queue, resourceProvide r, copier, uploader, maxTextureUpdates)); | |
| 32 } | 49 } |
| 33 | 50 |
| 34 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count) | 51 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count) |
| 35 { | 52 { |
| 36 if (queue->fullUploadSize() || queue->partialUploadSize()) { | 53 if (queue->fullUploadSize() || queue->partialUploadSize()) { |
| 37 if (uploader->isBusy()) | 54 if (uploader->isBusy()) |
| 38 return; | 55 return; |
| 39 | 56 |
| 40 uploader->beginUploads(); | 57 uploader->beginUploads(); |
| 41 | 58 |
| 42 size_t fullUploadCount = 0; | 59 size_t fullUploadCount = 0; |
| 43 while (queue->fullUploadSize() && fullUploadCount < count) { | 60 bool uploadMore = queue->fullUploadSize() && fullUploadCount < count; |
| 61 while (uploadMore) { | |
| 44 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload ()); | 62 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload ()); |
| 45 fullUploadCount++; | 63 fullUploadCount++; |
| 46 if (!(fullUploadCount % textureUploadFlushPeriod)) | 64 uploadMore = queue->fullUploadSize() && fullUploadCount < count; |
| 65 | |
| 66 // Flush periodically, but deffer our last flush until after uploade r->endUploads() | |
| 67 // in order to keep the query associated with endUploads grouped wit h our last texture upload. | |
| 68 if (!(fullUploadCount % textureUploadFlushPeriod) && uploadMore) | |
| 47 resourceProvider->shallowFlushIfSupported(); | 69 resourceProvider->shallowFlushIfSupported(); |
| 48 } | 70 } |
| 49 | 71 |
| 50 // Make sure there are no dangling uploads without a flush. | 72 ASSERT(queue->partialUploadSize() <= count); |
| 51 if (fullUploadCount % textureUploadFlushPeriod) | 73 bool needAnotherTick = queue->fullUploadSize() || ((count - fullUploadCo unt) < queue->partialUploadSize()); |
| 74 if (needAnotherTick) { | |
| 75 uploader->endUploads(); | |
| 52 resourceProvider->shallowFlushIfSupported(); | 76 resourceProvider->shallowFlushIfSupported(); |
| 53 | |
| 54 bool moreUploads = queue->fullUploadSize(); | |
| 55 | |
| 56 ASSERT(queue->partialUploadSize() <= count); | |
| 57 // We need another update batch if the number of updates remaining | |
| 58 // in |count| is greater than the remaining partial entries. | |
| 59 if ((count - fullUploadCount) < queue->partialUploadSize()) | |
| 60 moreUploads = true; | |
| 61 | |
| 62 if (moreUploads) { | |
| 63 uploader->endUploads(); | |
| 64 return; | 77 return; |
| 65 } | 78 } |
| 79 resourceProvider->shallowFlushIfSupported(); | |
| 66 | 80 |
| 67 size_t partialUploadCount = 0; | 81 size_t partialUploadCount = 0; |
| 68 while (queue->partialUploadSize()) { | 82 while (queue->partialUploadSize()) { |
| 69 uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpl oad()); | 83 uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpl oad()); |
|
nduca
2012/09/14 05:50:26
I think we should do partials all at once, and swa
brianderson
2012/09/14 19:12:00
Do you mean we should not upload fulls and partial
| |
| 70 partialUploadCount++; | 84 partialUploadCount++; |
| 71 if (!(partialUploadCount % textureUploadFlushPeriod)) | 85 |
| 86 // Flush periodically, but deffer our last flush until after uploade r->endUploads() | |
|
nduca
2012/09/14 05:50:26
deffer->defer
brianderson
2012/09/14 19:12:00
ok
| |
| 87 // in order to keep the query associated with endUploads grouped wit h our last texture upload. | |
| 88 if (!(partialUploadCount % textureUploadFlushPeriod) && queue->parti alUploadSize()) | |
| 72 resourceProvider->shallowFlushIfSupported(); | 89 resourceProvider->shallowFlushIfSupported(); |
| 73 } | 90 } |
| 74 | 91 |
| 75 // Make sure there are no dangling partial uploads without a flush. | |
| 76 if (partialUploadCount % textureUploadFlushPeriod) | |
| 77 resourceProvider->shallowFlushIfSupported(); | |
| 78 | |
| 79 uploader->endUploads(); | 92 uploader->endUploads(); |
| 93 resourceProvider->shallowFlushIfSupported(); | |
| 80 } | 94 } |
| 81 | 95 |
| 82 size_t copyCount = 0; | 96 size_t copyCount = 0; |
| 83 while (queue->copySize()) { | 97 while (queue->copySize()) { |
| 84 copier->copyTexture(queue->takeFirstCopy()); | 98 copier->copyTexture(queue->takeFirstCopy()); |
| 85 copyCount++; | 99 copyCount++; |
| 86 } | 100 } |
| 87 | 101 |
| 88 // If we've performed any texture copies, we need to insert a flush here int o the compositor context | 102 // If we've performed any texture copies, we need to insert a flush here int o the compositor context |
| 89 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of | 103 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of |
| 90 // our copy operations. | 104 // our copy operations. |
| 91 if (copyCount) | 105 if (copyCount) |
| 92 copier->flush(); | 106 copier->flush(); |
| 93 } | 107 } |
| 94 | 108 |
| 95 CCTextureUpdateController::CCTextureUpdateController(CCThread* thread, PassOwnPt r<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureCopi er* copier, TextureUploader* uploader) | 109 CCTextureUpdateController::CCTextureUpdateController(CCThread* thread, PassOwnPt r<CCTextureUpdateQueue> queue, CCResourceProvider* resourceProvider, TextureCopi er* copier, TextureUploader* uploader, size_t maxTextureUpdates) |
| 96 : m_timer(adoptPtr(new CCTimer(thread, this))) | 110 : m_timer(adoptPtr(new CCTimer(thread, this))) |
| 97 , m_queue(queue) | 111 , m_queue(queue) |
| 98 , m_resourceProvider(resourceProvider) | 112 , m_resourceProvider(resourceProvider) |
| 99 , m_copier(copier) | 113 , m_copier(copier) |
| 100 , m_uploader(uploader) | 114 , m_uploader(uploader) |
| 101 , m_monotonicTimeLimit(0) | 115 , m_monotonicTimeLimit(0) |
| 116 , m_textureUpdatesPerTick(maxTextureUpdates) | |
| 102 , m_firstUpdateAttempt(true) | 117 , m_firstUpdateAttempt(true) |
| 103 { | 118 { |
| 104 } | 119 } |
| 105 | 120 |
| 106 CCTextureUpdateController::~CCTextureUpdateController() | 121 CCTextureUpdateController::~CCTextureUpdateController() |
| 107 { | 122 { |
| 108 } | 123 } |
| 109 | 124 |
| 110 bool CCTextureUpdateController::hasMoreUpdates() const | 125 bool CCTextureUpdateController::hasMoreUpdates() const |
| 111 { | 126 { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 142 return monotonicallyIncreasingTime(); | 157 return monotonicallyIncreasingTime(); |
| 143 } | 158 } |
| 144 | 159 |
| 145 double CCTextureUpdateController::updateMoreTexturesTime() const | 160 double CCTextureUpdateController::updateMoreTexturesTime() const |
| 146 { | 161 { |
| 147 return textureUpdateTickRate; | 162 return textureUpdateTickRate; |
| 148 } | 163 } |
| 149 | 164 |
| 150 size_t CCTextureUpdateController::updateMoreTexturesSize() const | 165 size_t CCTextureUpdateController::updateMoreTexturesSize() const |
| 151 { | 166 { |
| 152 return textureUpdatesPerTick; | 167 return m_textureUpdatesPerTick; |
| 153 } | 168 } |
| 154 | 169 |
| 155 void CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() | 170 void CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() |
| 156 { | 171 { |
| 157 bool hasTimeRemaining = monotonicTimeNow() < m_monotonicTimeLimit - updateMo reTexturesTime(); | 172 bool hasTimeRemaining = monotonicTimeNow() < m_monotonicTimeLimit - updateMo reTexturesTime(); |
| 158 if (hasTimeRemaining) | 173 if (hasTimeRemaining) |
| 159 updateMoreTexturesNow(); | 174 updateMoreTexturesNow(); |
| 160 } | 175 } |
| 161 | 176 |
| 162 void CCTextureUpdateController::updateMoreTexturesNow() | 177 void CCTextureUpdateController::updateMoreTexturesNow() |
| 163 { | 178 { |
| 164 m_timer->startOneShot(updateMoreTexturesTime()); | 179 m_timer->startOneShot(updateMoreTexturesTime()); |
| 165 updateTextures(m_resourceProvider, m_copier, m_uploader, m_queue.get(), upda teMoreTexturesSize()); | 180 updateTextures(m_resourceProvider, m_copier, m_uploader, m_queue.get(), upda teMoreTexturesSize()); |
| 166 } | 181 } |
| 167 | 182 |
| 168 } | 183 } |
| OLD | NEW |