OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/software_frame_manager.h" | 5 #include "content/browser/renderer_host/software_frame_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
10 #include "base/sys_info.h" | |
11 #include "content/browser/renderer_host/dip_util.h" | 10 #include "content/browser/renderer_host/dip_util.h" |
12 #include "content/public/browser/user_metrics.h" | 11 #include "content/public/browser/user_metrics.h" |
13 | 12 |
14 namespace { | 13 namespace { |
15 | 14 |
16 void ReleaseMailbox(scoped_refptr<content::SoftwareFrame> frame, | 15 void ReleaseMailbox(scoped_refptr<content::SoftwareFrame> frame, |
17 unsigned sync_point, | 16 unsigned sync_point, |
18 bool lost_resource) {} | 17 bool lost_resource) {} |
19 | 18 |
20 } // namespace | 19 } // namespace |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 163 } |
165 | 164 |
166 bool SoftwareFrameManager::HasCurrentFrame() const { | 165 bool SoftwareFrameManager::HasCurrentFrame() const { |
167 return current_frame_.get() ? true : false; | 166 return current_frame_.get() ? true : false; |
168 } | 167 } |
169 | 168 |
170 void SoftwareFrameManager::DiscardCurrentFrame() { | 169 void SoftwareFrameManager::DiscardCurrentFrame() { |
171 if (!HasCurrentFrame()) | 170 if (!HasCurrentFrame()) |
172 return; | 171 return; |
173 current_frame_ = NULL; | 172 current_frame_ = NULL; |
174 SoftwareFrameMemoryManager::GetInstance()->RemoveFrame(this); | 173 RendererFrameManager::GetInstance()->RemoveFrame(this); |
175 } | 174 } |
176 | 175 |
177 void SoftwareFrameManager::SwapToNewFrameComplete(bool visible) { | 176 void SoftwareFrameManager::SwapToNewFrameComplete(bool visible) { |
178 DCHECK(HasCurrentFrame()); | 177 DCHECK(HasCurrentFrame()); |
179 SoftwareFrameMemoryManager::GetInstance()->AddFrame(this, visible); | 178 RendererFrameManager::GetInstance()->AddFrame(this, visible); |
180 } | 179 } |
181 | 180 |
182 void SoftwareFrameManager::SetVisibility(bool visible) { | 181 void SoftwareFrameManager::SetVisibility(bool visible) { |
183 if (HasCurrentFrame()) { | 182 if (HasCurrentFrame()) { |
184 SoftwareFrameMemoryManager::GetInstance()->SetFrameVisibility(this, | 183 RendererFrameManager::GetInstance()->SetFrameVisibility(this, visible); |
185 visible); | |
186 } | 184 } |
187 } | 185 } |
188 | 186 |
189 void SoftwareFrameManager::GetCurrentFrameMailbox( | 187 void SoftwareFrameManager::GetCurrentFrameMailbox( |
190 cc::TextureMailbox* mailbox, | 188 cc::TextureMailbox* mailbox, |
191 scoped_ptr<cc::SingleReleaseCallback>* callback) { | 189 scoped_ptr<cc::SingleReleaseCallback>* callback) { |
192 DCHECK(HasCurrentFrame()); | 190 DCHECK(HasCurrentFrame()); |
193 *mailbox = cc::TextureMailbox( | 191 *mailbox = cc::TextureMailbox( |
194 current_frame_->shared_memory_.get(), current_frame_->frame_size_pixels_); | 192 current_frame_->shared_memory_.get(), current_frame_->frame_size_pixels_); |
195 *callback = cc::SingleReleaseCallback::Create( | 193 *callback = cc::SingleReleaseCallback::Create( |
(...skipping 17 matching lines...) Expand all Loading... |
213 return current_frame_->frame_size_dip_; | 211 return current_frame_->frame_size_dip_; |
214 } | 212 } |
215 | 213 |
216 void SoftwareFrameManager::EvictCurrentFrame() { | 214 void SoftwareFrameManager::EvictCurrentFrame() { |
217 DCHECK(HasCurrentFrame()); | 215 DCHECK(HasCurrentFrame()); |
218 DiscardCurrentFrame(); | 216 DiscardCurrentFrame(); |
219 if (client_) | 217 if (client_) |
220 client_->ReleaseReferencesToSoftwareFrame(); | 218 client_->ReleaseReferencesToSoftwareFrame(); |
221 } | 219 } |
222 | 220 |
223 //////////////////////////////////////////////////////////////////////////////// | |
224 // SoftwareFrameMemoryManager | |
225 | |
226 SoftwareFrameMemoryManager* SoftwareFrameMemoryManager::GetInstance() { | |
227 return Singleton<SoftwareFrameMemoryManager>::get(); | |
228 } | |
229 | |
230 void SoftwareFrameMemoryManager::AddFrame(SoftwareFrameManager* frame, | |
231 bool visible) { | |
232 RemoveFrame(frame); | |
233 if (visible) | |
234 visible_frames_.insert(frame); | |
235 else | |
236 hidden_frames_.push_front(frame); | |
237 CullHiddenFrames(); | |
238 } | |
239 | |
240 void SoftwareFrameMemoryManager::RemoveFrame(SoftwareFrameManager* frame) { | |
241 visible_frames_.erase(frame); | |
242 hidden_frames_.remove(frame); | |
243 } | |
244 | |
245 void SoftwareFrameMemoryManager::SetFrameVisibility(SoftwareFrameManager* frame, | |
246 bool visible) { | |
247 if (visible) { | |
248 hidden_frames_.remove(frame); | |
249 visible_frames_.insert(frame); | |
250 } else { | |
251 visible_frames_.erase(frame); | |
252 hidden_frames_.push_front(frame); | |
253 CullHiddenFrames(); | |
254 } | |
255 } | |
256 | |
257 SoftwareFrameMemoryManager::SoftwareFrameMemoryManager() | |
258 : max_number_of_saved_frames_( | |
259 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256))) {} | |
260 | |
261 SoftwareFrameMemoryManager::~SoftwareFrameMemoryManager() {} | |
262 | |
263 void SoftwareFrameMemoryManager::CullHiddenFrames() { | |
264 while (!hidden_frames_.empty() && | |
265 hidden_frames_.size() + visible_frames_.size() > | |
266 max_number_of_saved_frames()) { | |
267 size_t old_size = hidden_frames_.size(); | |
268 // Should remove self from list. | |
269 hidden_frames_.back()->EvictCurrentFrame(); | |
270 DCHECK_EQ(hidden_frames_.size() + 1, old_size); | |
271 } | |
272 } | |
273 | |
274 } // namespace content | 221 } // namespace content |
OLD | NEW |