| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 } // anonymous namespace | 28 } // anonymous namespace |
| 29 | 29 |
| 30 namespace cc { | 30 namespace cc { |
| 31 | 31 |
| 32 size_t CCTextureUpdateController::maxPartialTextureUpdates() | 32 size_t CCTextureUpdateController::maxPartialTextureUpdates() |
| 33 { | 33 { |
| 34 return textureUpdatesPerTick; | 34 return textureUpdatesPerTick; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi
der, TextureUploader* uploader, CCTextureUpdateQueue* queue, size_t count) | 37 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi
der, TextureUploader* uploader, CCTextureUpdateQueue* queue) |
| 38 { | 38 { |
| 39 if (queue->fullUploadSize() || queue->partialUploadSize()) { | 39 size_t uploadCount = 0; |
| 40 if (uploader->isBusy()) | 40 while (queue->fullUploadSize()) { |
| 41 return; | 41 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 42 | |
| 43 uploader->beginUploads(); | |
| 44 | |
| 45 size_t fullUploadCount = 0; | |
| 46 while (queue->fullUploadSize() && fullUploadCount < count) { | |
| 47 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload
()); | |
| 48 fullUploadCount++; | |
| 49 if (!(fullUploadCount % textureUploadFlushPeriod)) | |
| 50 resourceProvider->shallowFlushIfSupported(); | |
| 51 } | |
| 52 | |
| 53 // Make sure there are no dangling uploads without a flush. | |
| 54 if (fullUploadCount % textureUploadFlushPeriod) | |
| 55 resourceProvider->shallowFlushIfSupported(); | 42 resourceProvider->shallowFlushIfSupported(); |
| 56 | 43 |
| 57 bool moreUploads = queue->fullUploadSize(); | 44 uploader->uploadTexture( |
| 45 resourceProvider, queue->takeFirstFullUpload()); |
| 46 uploadCount++; |
| 47 } |
| 58 | 48 |
| 59 ASSERT(queue->partialUploadSize() <= count); | 49 while (queue->partialUploadSize()) { |
| 60 // We need another update batch if the number of updates remaining | 50 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) |
| 61 // in |count| is greater than the remaining partial entries. | |
| 62 if ((count - fullUploadCount) < queue->partialUploadSize()) | |
| 63 moreUploads = true; | |
| 64 | |
| 65 if (moreUploads) { | |
| 66 uploader->endUploads(); | |
| 67 return; | |
| 68 } | |
| 69 | |
| 70 size_t partialUploadCount = 0; | |
| 71 while (queue->partialUploadSize()) { | |
| 72 uploader->uploadTexture(resourceProvider, queue->takeFirstPartialUpl
oad()); | |
| 73 partialUploadCount++; | |
| 74 if (!(partialUploadCount % textureUploadFlushPeriod)) | |
| 75 resourceProvider->shallowFlushIfSupported(); | |
| 76 } | |
| 77 | |
| 78 // Make sure there are no dangling partial uploads without a flush. | |
| 79 if (partialUploadCount % textureUploadFlushPeriod) | |
| 80 resourceProvider->shallowFlushIfSupported(); | 51 resourceProvider->shallowFlushIfSupported(); |
| 81 | 52 |
| 82 uploader->endUploads(); | 53 uploader->uploadTexture( |
| 54 resourceProvider, queue->takeFirstPartialUpload()); |
| 55 uploadCount++; |
| 83 } | 56 } |
| 84 | 57 |
| 85 TextureCopier* copier = resourceProvider->textureCopier(); | 58 if (uploadCount) |
| 86 size_t copyCount = 0; | 59 resourceProvider->shallowFlushIfSupported(); |
| 87 while (queue->copySize()) { | 60 |
| 88 copier->copyTexture(queue->takeFirstCopy()); | 61 if (queue->copySize()) { |
| 89 copyCount++; | 62 TextureCopier* copier = resourceProvider->textureCopier(); |
| 63 while (queue->copySize()) |
| 64 copier->copyTexture(queue->takeFirstCopy()); |
| 65 |
| 66 // If we've performed any texture copies, we need to insert a flush |
| 67 // here into the compositor context before letting the main thread |
| 68 // proceed as it may make draw calls to the source texture of one of |
| 69 // our copy operations. |
| 70 copier->flush(); |
| 90 } | 71 } |
| 91 | |
| 92 // If we've performed any texture copies, we need to insert a flush here int
o the compositor context | |
| 93 // before letting the main thread proceed as it may make draw calls to the s
ource texture of one of | |
| 94 // our copy operations. | |
| 95 if (copyCount) | |
| 96 copier->flush(); | |
| 97 } | 72 } |
| 98 | 73 |
| 99 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl
ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour
ceProvider* resourceProvider, TextureUploader* uploader) | 74 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl
ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour
ceProvider* resourceProvider, TextureUploader* uploader) |
| 100 : m_client(client) | 75 : m_client(client) |
| 101 , m_timer(adoptPtr(new CCTimer(thread, this))) | 76 , m_timer(adoptPtr(new CCTimer(thread, this))) |
| 102 , m_queue(queue) | 77 , m_queue(queue) |
| 103 , m_resourceProvider(resourceProvider) | 78 , m_resourceProvider(resourceProvider) |
| 104 , m_uploader(uploader) | 79 , m_uploader(uploader) |
| 105 , m_monotonicTimeLimit(0) | 80 , m_monotonicTimeLimit(0) |
| 106 , m_firstUpdateAttempt(true) | 81 , m_firstUpdateAttempt(true) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 if (!updateMoreTexturesIfEnoughTimeRemaining()) | 105 if (!updateMoreTexturesIfEnoughTimeRemaining()) |
| 131 m_timer->startOneShot(0); | 106 m_timer->startOneShot(0); |
| 132 | 107 |
| 133 m_firstUpdateAttempt = false; | 108 m_firstUpdateAttempt = false; |
| 134 } else | 109 } else |
| 135 updateMoreTexturesNow(); | 110 updateMoreTexturesNow(); |
| 136 } | 111 } |
| 137 | 112 |
| 138 void CCTextureUpdateController::finalize() | 113 void CCTextureUpdateController::finalize() |
| 139 { | 114 { |
| 140 while (m_queue->hasMoreUpdates()) | 115 updateTextures(m_resourceProvider, m_uploader, m_queue.get()); |
| 141 updateTextures(m_resourceProvider, m_uploader, m_queue.get(), | |
| 142 updateMoreTexturesSize()); | |
| 143 } | 116 } |
| 144 | 117 |
| 145 void CCTextureUpdateController::onTimerFired() | 118 void CCTextureUpdateController::onTimerFired() |
| 146 { | 119 { |
| 147 if (!updateMoreTexturesIfEnoughTimeRemaining()) | 120 if (!updateMoreTexturesIfEnoughTimeRemaining()) |
| 148 m_client->readyToFinalizeTextureUpdates(); | 121 m_client->readyToFinalizeTextureUpdates(); |
| 149 } | 122 } |
| 150 | 123 |
| 151 double CCTextureUpdateController::monotonicTimeNow() const | 124 double CCTextureUpdateController::monotonicTimeNow() const |
| 152 { | 125 { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 178 } |
| 206 | 179 |
| 207 // Make sure there are no dangling partial uploads without a flush. | 180 // Make sure there are no dangling partial uploads without a flush. |
| 208 if (uploadCount % textureUploadFlushPeriod) | 181 if (uploadCount % textureUploadFlushPeriod) |
| 209 m_resourceProvider->shallowFlushIfSupported(); | 182 m_resourceProvider->shallowFlushIfSupported(); |
| 210 | 183 |
| 211 m_uploader->endUploads(); | 184 m_uploader->endUploads(); |
| 212 } | 185 } |
| 213 | 186 |
| 214 } | 187 } |
| OLD | NEW |