Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: cc/texture_update_controller.cc

Issue 11189043: cc: Rename cc classes and members to match filenames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "CCResourceProvider.h" 9 #include "CCResourceProvider.h"
10 #include "TraceEvent.h" 10 #include "TraceEvent.h"
(...skipping 16 matching lines...) Expand all
27 // Flush interval when performing texture uploads. 27 // Flush interval when performing texture uploads.
28 const int textureUploadFlushPeriod = 4; 28 const int textureUploadFlushPeriod = 4;
29 29
30 // Number of blocking update intervals to allow. 30 // Number of blocking update intervals to allow.
31 const size_t maxBlockingUpdateIntervals = 4; 31 const size_t maxBlockingUpdateIntervals = 4;
32 32
33 } // namespace 33 } // namespace
34 34
35 namespace cc { 35 namespace cc {
36 36
37 size_t CCTextureUpdateController::maxPartialTextureUpdates() 37 size_t TextureUpdateController::maxPartialTextureUpdates()
38 { 38 {
39 return partialTextureUpdatesMax; 39 return partialTextureUpdatesMax;
40 } 40 }
41 41
42 size_t CCTextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploade r) 42 size_t TextureUpdateController::maxFullUpdatesPerTick(TextureUploader* uploader)
43 { 43 {
44 double texturesPerSecond = uploader->estimatedTexturesPerSecond(); 44 double texturesPerSecond = uploader->estimatedTexturesPerSecond();
45 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond); 45 size_t texturesPerTick = floor(textureUpdateTickRate * texturesPerSecond);
46 return texturesPerTick ? texturesPerTick : 1; 46 return texturesPerTick ? texturesPerTick : 1;
47 } 47 }
48 48
49 CCTextureUpdateController::CCTextureUpdateController(CCTextureUpdateControllerCl ient* client, CCThread* thread, scoped_ptr<CCTextureUpdateQueue> queue, CCResour ceProvider* resourceProvider, TextureUploader* uploader) 49 TextureUpdateController::TextureUpdateController(TextureUpdateControllerClient* client, Thread* thread, scoped_ptr<TextureUpdateQueue> queue, ResourceProvider* resourceProvider, TextureUploader* uploader)
50 : m_client(client) 50 : m_client(client)
51 , m_timer(new CCTimer(thread, this)) 51 , m_timer(new Timer(thread, this))
52 , m_queue(queue.Pass()) 52 , m_queue(queue.Pass())
53 , m_resourceProvider(resourceProvider) 53 , m_resourceProvider(resourceProvider)
54 , m_uploader(uploader) 54 , m_uploader(uploader)
55 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader)) 55 , m_textureUpdatesPerTick(maxFullUpdatesPerTick(uploader))
56 , m_firstUpdateAttempt(true) 56 , m_firstUpdateAttempt(true)
57 { 57 {
58 } 58 }
59 59
60 CCTextureUpdateController::~CCTextureUpdateController() 60 TextureUpdateController::~TextureUpdateController()
61 { 61 {
62 } 62 }
63 63
64 void CCTextureUpdateController::performMoreUpdates( 64 void TextureUpdateController::performMoreUpdates(
65 base::TimeTicks timeLimit) 65 base::TimeTicks timeLimit)
66 { 66 {
67 m_timeLimit = timeLimit; 67 m_timeLimit = timeLimit;
68 68
69 // Update already in progress. 69 // Update already in progress.
70 if (m_timer->isActive()) 70 if (m_timer->isActive())
71 return; 71 return;
72 72
73 // Call updateMoreTexturesNow() directly unless it's the first update 73 // Call updateMoreTexturesNow() directly unless it's the first update
74 // attempt. This ensures that we empty the update queue in a finite 74 // attempt. This ensures that we empty the update queue in a finite
75 // amount of time. 75 // amount of time.
76 if (m_firstUpdateAttempt) { 76 if (m_firstUpdateAttempt) {
77 // Post a 0-delay task when no updates were left. When it runs, 77 // Post a 0-delay task when no updates were left. When it runs,
78 // readyToFinalizeTextureUpdates() will be called. 78 // readyToFinalizeTextureUpdates() will be called.
79 if (!updateMoreTexturesIfEnoughTimeRemaining()) 79 if (!updateMoreTexturesIfEnoughTimeRemaining())
80 m_timer->startOneShot(0); 80 m_timer->startOneShot(0);
81 81
82 m_firstUpdateAttempt = false; 82 m_firstUpdateAttempt = false;
83 } else 83 } else
84 updateMoreTexturesNow(); 84 updateMoreTexturesNow();
85 } 85 }
86 86
87 void CCTextureUpdateController::discardUploadsToEvictedResources() 87 void TextureUpdateController::discardUploadsToEvictedResources()
88 { 88 {
89 m_queue->clearUploadsToEvictedResources(); 89 m_queue->clearUploadsToEvictedResources();
90 } 90 }
91 91
92 void CCTextureUpdateController::finalize() 92 void TextureUpdateController::finalize()
93 { 93 {
94 size_t uploadCount = 0; 94 size_t uploadCount = 0;
95 while (m_queue->fullUploadSize()) { 95 while (m_queue->fullUploadSize()) {
96 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) 96 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
97 m_resourceProvider->shallowFlushIfSupported(); 97 m_resourceProvider->shallowFlushIfSupported();
98 98
99 m_uploader->uploadTexture( 99 m_uploader->uploadTexture(
100 m_resourceProvider, m_queue->takeFirstFullUpload()); 100 m_resourceProvider, m_queue->takeFirstFullUpload());
101 uploadCount++; 101 uploadCount++;
102 } 102 }
(...skipping 16 matching lines...) Expand all
119 copier->copyTexture(m_queue->takeFirstCopy()); 119 copier->copyTexture(m_queue->takeFirstCopy());
120 120
121 // If we've performed any texture copies, we need to insert a flush 121 // If we've performed any texture copies, we need to insert a flush
122 // here into the compositor context before letting the main thread 122 // here into the compositor context before letting the main thread
123 // proceed as it may make draw calls to the source texture of one of 123 // proceed as it may make draw calls to the source texture of one of
124 // our copy operations. 124 // our copy operations.
125 copier->flush(); 125 copier->flush();
126 } 126 }
127 } 127 }
128 128
129 void CCTextureUpdateController::onTimerFired() 129 void TextureUpdateController::onTimerFired()
130 { 130 {
131 if (!updateMoreTexturesIfEnoughTimeRemaining()) 131 if (!updateMoreTexturesIfEnoughTimeRemaining())
132 m_client->readyToFinalizeTextureUpdates(); 132 m_client->readyToFinalizeTextureUpdates();
133 } 133 }
134 134
135 base::TimeTicks CCTextureUpdateController::now() const 135 base::TimeTicks TextureUpdateController::now() const
136 { 136 {
137 return base::TimeTicks::Now(); 137 return base::TimeTicks::Now();
138 } 138 }
139 139
140 base::TimeDelta CCTextureUpdateController::updateMoreTexturesTime() const 140 base::TimeDelta TextureUpdateController::updateMoreTexturesTime() const
141 { 141 {
142 return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000); 142 return base::TimeDelta::FromMilliseconds(textureUpdateTickRate * 1000);
143 } 143 }
144 144
145 size_t CCTextureUpdateController::updateMoreTexturesSize() const 145 size_t TextureUpdateController::updateMoreTexturesSize() const
146 { 146 {
147 return m_textureUpdatesPerTick; 147 return m_textureUpdatesPerTick;
148 } 148 }
149 149
150 size_t CCTextureUpdateController::maxBlockingUpdates() const 150 size_t TextureUpdateController::maxBlockingUpdates() const
151 { 151 {
152 return updateMoreTexturesSize() * maxBlockingUpdateIntervals; 152 return updateMoreTexturesSize() * maxBlockingUpdateIntervals;
153 } 153 }
154 154
155 bool CCTextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining() 155 bool TextureUpdateController::updateMoreTexturesIfEnoughTimeRemaining()
156 { 156 {
157 // Blocking uploads will increase when we're too aggressive in our upload 157 // Blocking uploads will increase when we're too aggressive in our upload
158 // time estimate. We use a different timeout here to prevent unnecessary 158 // time estimate. We use a different timeout here to prevent unnecessary
159 // amounts of idle time when blocking uploads have reached the max. 159 // amounts of idle time when blocking uploads have reached the max.
160 if (m_uploader->numBlockingUploads() >= maxBlockingUpdates()) { 160 if (m_uploader->numBlockingUploads() >= maxBlockingUpdates()) {
161 m_timer->startOneShot(uploaderBusyTickRate); 161 m_timer->startOneShot(uploaderBusyTickRate);
162 return true; 162 return true;
163 } 163 }
164 164
165 if (!m_queue->fullUploadSize()) 165 if (!m_queue->fullUploadSize())
166 return false; 166 return false;
167 167
168 bool hasTimeRemaining = m_timeLimit.is_null() || 168 bool hasTimeRemaining = m_timeLimit.is_null() ||
169 this->now() < m_timeLimit - updateMoreTexturesTime(); 169 this->now() < m_timeLimit - updateMoreTexturesTime();
170 if (hasTimeRemaining) 170 if (hasTimeRemaining)
171 updateMoreTexturesNow(); 171 updateMoreTexturesNow();
172 172
173 return true; 173 return true;
174 } 174 }
175 175
176 void CCTextureUpdateController::updateMoreTexturesNow() 176 void TextureUpdateController::updateMoreTexturesNow()
177 { 177 {
178 size_t uploads = std::min( 178 size_t uploads = std::min(
179 m_queue->fullUploadSize(), updateMoreTexturesSize()); 179 m_queue->fullUploadSize(), updateMoreTexturesSize());
180 m_timer->startOneShot( 180 m_timer->startOneShot(
181 updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() * 181 updateMoreTexturesTime().InSecondsF() / updateMoreTexturesSize() *
182 uploads); 182 uploads);
183 183
184 if (!uploads) 184 if (!uploads)
185 return; 185 return;
186 186
187 size_t uploadCount = 0; 187 size_t uploadCount = 0;
188 while (m_queue->fullUploadSize() && uploadCount < uploads) { 188 while (m_queue->fullUploadSize() && uploadCount < uploads) {
189 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount) 189 if (!(uploadCount % textureUploadFlushPeriod) && uploadCount)
190 m_resourceProvider->shallowFlushIfSupported(); 190 m_resourceProvider->shallowFlushIfSupported();
191 m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUplo ad()); 191 m_uploader->uploadTexture(m_resourceProvider, m_queue->takeFirstFullUplo ad());
192 uploadCount++; 192 uploadCount++;
193 } 193 }
194 m_resourceProvider->shallowFlushIfSupported(); 194 m_resourceProvider->shallowFlushIfSupported();
195 } 195 }
196 196
197 } // namespace cc 197 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698