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; |
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.
| |
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; | |
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.
| |
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 // Measured in seconds. | 26 // Measured in seconds. |
23 static const double uploaderBusyTickRate = 0.001; | 27 static const double uploaderBusyTickRate = 0.001; |
24 | 28 |
25 // Flush interval when performing texture uploads. | 29 // Flush interval when performing texture uploads. |
26 static const int textureUploadFlushPeriod = 4; | 30 static const int textureUploadFlushPeriod = 4; |
27 | 31 |
28 } // anonymous namespace | 32 } // anonymous namespace |
29 | 33 |
30 namespace cc { | 34 namespace cc { |
31 | 35 |
32 size_t CCTextureUpdateController::maxPartialTextureUpdates() | 36 size_t CCTextureUpdateController::maxPartialTextureUpdates() |
33 { | 37 { |
34 return textureUpdatesPerTick; | 38 return textureUpdatesPerFullTickMin; |
39 } | |
40 | |
41 size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploade r) | |
42 { | |
43 double texturesPerSecond = uploader->estimatedPixelsPerSecond() / pixelsPerT exture; | |
44 | |
45 return std::max(textureUpdatesPerFullTickMin, | |
46 (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.
| |
35 } | 47 } |
36 | 48 |
37 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count) | 49 void CCTextureUpdateController::updateTextures(CCResourceProvider* resourceProvi der, TextureCopier* copier, TextureUploader* uploader, CCTextureUpdateQueue* que ue, size_t count) |
38 { | 50 { |
51 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.
| |
39 if (queue->fullUploadSize() || queue->partialUploadSize()) { | 52 if (queue->fullUploadSize() || queue->partialUploadSize()) { |
40 if (uploader->isBusy()) | 53 if (uploader->isBusy()) |
41 return; | 54 return; |
42 | 55 |
43 uploader->beginUploads(); | 56 uploader->beginUploads(); |
44 | 57 |
45 size_t fullUploadCount = 0; | 58 size_t fullUploadCount = 0; |
46 while (queue->fullUploadSize() && fullUploadCount < count) { | 59 if (queue->fullUploadSize()) { |
47 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUpload ()); | 60 while (queue->fullUploadSize() && fullUploadCount < count) { |
48 fullUploadCount++; | 61 if (!(fullUploadCount % textureUploadFlushPeriod) && fullUploadC ount) |
49 if (!(fullUploadCount % textureUploadFlushPeriod)) | 62 resourceProvider->shallowFlushIfSupported(); |
63 uploader->uploadTexture(resourceProvider, queue->takeFirstFullUp load()); | |
64 fullUploadCount++; | |
65 } | |
66 | |
67 bool cantUpdloadAllPartials = (count - fullUploadCount) < queue->par tialUploadSize(); | |
reveman
2012/09/18 05:30:35
nit: spelling
| |
68 if (cantUpdloadAllPartials) { | |
reveman
2012/09/18 05:30:35
here too
| |
69 uploader->endUploads(); | |
50 resourceProvider->shallowFlushIfSupported(); | 70 resourceProvider->shallowFlushIfSupported(); |
71 return; | |
72 } | |
51 } | 73 } |
52 | 74 |
53 // Make sure there are no dangling uploads without a flush. | 75 ASSERT(queue->partialUploadSize() <= (count - fullUploadCount)); |
54 if (fullUploadCount % textureUploadFlushPeriod) | |
55 resourceProvider->shallowFlushIfSupported(); | |
56 | 76 |
57 bool moreUploads = queue->fullUploadSize(); | 77 size_t partialUploadCount = 0; |
58 | 78 if (queue->partialUploadSize()) { |
59 ASSERT(queue->partialUploadSize() <= count); | 79 if (fullUploadCount) |
60 // We need another update batch if the number of updates remaining | 80 resourceProvider->shallowFlushIfSupported(); |
61 // in |count| is greater than the remaining partial entries. | 81 while (queue->partialUploadSize()) { |
62 if ((count - fullUploadCount) < queue->partialUploadSize()) | 82 if (!(partialUploadCount % textureUploadFlushPeriod) && partialU ploadCount) |
63 moreUploads = true; | 83 resourceProvider->shallowFlushIfSupported(); |
64 | 84 uploader->uploadTexture(resourceProvider, queue->takeFirstPartia lUpload()); |
65 if (moreUploads) { | 85 partialUploadCount++; |
66 uploader->endUploads(); | 86 } |
67 return; | |
68 } | 87 } |
69 | 88 |
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(); | |
81 | |
82 uploader->endUploads(); | 89 uploader->endUploads(); |
90 resourceProvider->shallowFlushIfSupported(); | |
83 } | 91 } |
84 | 92 |
85 size_t copyCount = 0; | 93 size_t copyCount = 0; |
86 while (queue->copySize()) { | 94 while (queue->copySize()) { |
87 copier->copyTexture(queue->takeFirstCopy()); | 95 copier->copyTexture(queue->takeFirstCopy()); |
88 copyCount++; | 96 copyCount++; |
89 } | 97 } |
90 | 98 |
91 // If we've performed any texture copies, we need to insert a flush here int o the compositor context | 99 // If we've performed any texture copies, we need to insert a flush here int o the compositor context |
92 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of | 100 // before letting the main thread proceed as it may make draw calls to the s ource texture of one of |
93 // our copy operations. | 101 // our copy operations. |
94 if (copyCount) | 102 if (copyCount) |
95 copier->flush(); | 103 copier->flush(); |
96 } | 104 } |
97 | 105 |
98 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) | 106 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, PassOwnPtr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureCopier* copier, TextureUploader* uploader) |
99 : m_client(client) | 107 : m_client(client) |
100 , m_timer(adoptPtr(new CCTimer(thread, this))) | 108 , m_timer(adoptPtr(new CCTimer(thread, this))) |
101 , m_queue(queue) | 109 , m_queue(queue) |
102 , m_resourceProvider(resourceProvider) | 110 , m_resourceProvider(resourceProvider) |
103 , m_copier(copier) | 111 , m_copier(copier) |
104 , m_uploader(uploader) | 112 , m_uploader(uploader) |
105 , m_monotonicTimeLimit(0) | 113 , m_monotonicTimeLimit(0) |
114 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader)) | |
106 , m_firstUpdateAttempt(true) | 115 , m_firstUpdateAttempt(true) |
107 { | 116 { |
108 } | 117 } |
109 | 118 |
110 CCTextureUpdateController::~CCTextureUpdateController() | 119 CCTextureUpdateController::~CCTextureUpdateController() |
111 { | 120 { |
112 } | 121 } |
113 | 122 |
114 void CCTextureUpdateController::performMoreUpdates( | 123 void CCTextureUpdateController::performMoreUpdates( |
115 double monotonicTimeLimit) | 124 double monotonicTimeLimit) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 return monotonicallyIncreasingTime(); | 162 return monotonicallyIncreasingTime(); |
154 } | 163 } |
155 | 164 |
156 double CCTextureUpdateController::updateMoreTexturesTime() const | 165 double CCTextureUpdateController::updateMoreTexturesTime() const |
157 { | 166 { |
158 return textureUpdateTickRate; | 167 return textureUpdateTickRate; |
159 } | 168 } |
160 | 169 |
161 size_t CCTextureUpdateController::updateMoreTexturesSize() const | 170 size_t CCTextureUpdateController::updateMoreTexturesSize() const |
162 { | 171 { |
163 return textureUpdatesPerTick; | 172 return m_textureUpdatesPerTick; |
164 } | 173 } |
165 | 174 |
166 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() | 175 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() |
167 { | 176 { |
168 // Uploader might be busy when we're too aggressive in our upload time | 177 // Uploader might be busy when we're too aggressive in our upload time |
169 // estimate. We use a different timeout here to prevent unnecessary | 178 // estimate. We use a different timeout here to prevent unnecessary |
170 // amounts of idle time. | 179 // amounts of idle time. |
171 if (m_uploader->isBusy()) { | 180 if (m_uploader->isBusy()) { |
172 m_timer->startOneShot(uploaderBusyTickRate); | 181 m_timer->startOneShot(uploaderBusyTickRate); |
173 return true; | 182 return true; |
(...skipping 12 matching lines...) Expand all Loading... | |
186 void CCTextureUpdateController::updateMoreTexturesNow() | 195 void CCTextureUpdateController::updateMoreTexturesNow() |
187 { | 196 { |
188 size_t uploads = std::min( | 197 size_t uploads = std::min( |
189 m_queue->fullUploadSize(), updateMoreTexturesSize()); | 198 m_queue->fullUploadSize(), updateMoreTexturesSize()); |
190 m_timer->startOneShot( | 199 m_timer->startOneShot( |
191 updateMoreTexturesTime() / updateMoreTexturesSize() * uploads); | 200 updateMoreTexturesTime() / updateMoreTexturesSize() * uploads); |
192 | 201 |
193 if (!uploads) | 202 if (!uploads) |
194 return; | 203 return; |
195 | 204 |
205 size_t fullUploadCount = 0; | |
196 m_uploader->beginUploads(); | 206 m_uploader->beginUploads(); |
197 | 207 while (m_queue->fullUploadSize() && fullUploadCount < uploads) { |
198 size_t uploadCount = 0; | 208 if (!(fullUploadCount % textureUploadFlushPeriod) && fullUploadCount) |
199 while (uploads--) { | |
200 m_uploader->uploadTexture( | |
201 m_resourceProvider, m_queue->takeFirstFullUpload()); | |
202 uploadCount++; | |
203 if (!(uploadCount % textureUploadFlushPeriod)) | |
204 m_resourceProvider->shallowFlushIfSupported(); | 209 m_resourceProvider->shallowFlushIfSupported(); |
210 m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUplo ad()); | |
211 fullUploadCount++; | |
205 } | 212 } |
206 | |
207 // Make sure there are no dangling partial uploads without a flush. | |
208 if (uploadCount % textureUploadFlushPeriod) | |
209 m_resourceProvider->shallowFlushIfSupported(); | |
210 | |
211 m_uploader->endUploads(); | 213 m_uploader->endUploads(); |
214 m_resourceProvider->shallowFlushIfSupported(); | |
212 } | 215 } |
213 | 216 |
214 } | 217 } |
OLD | NEW |