OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "cc/font_atlas.h" | 11 #include "cc/font_atlas.h" |
12 #include "cc/graphics_context.h" | |
13 #include "cc/heads_up_display_layer.h" | 12 #include "cc/heads_up_display_layer.h" |
14 #include "cc/heads_up_display_layer_impl.h" | 13 #include "cc/heads_up_display_layer_impl.h" |
15 #include "cc/layer.h" | 14 #include "cc/layer.h" |
16 #include "cc/layer_animation_controller.h" | 15 #include "cc/layer_animation_controller.h" |
17 #include "cc/layer_iterator.h" | 16 #include "cc/layer_iterator.h" |
18 #include "cc/layer_tree_host_client.h" | 17 #include "cc/layer_tree_host_client.h" |
19 #include "cc/layer_tree_host_common.h" | 18 #include "cc/layer_tree_host_common.h" |
20 #include "cc/layer_tree_host_impl.h" | 19 #include "cc/layer_tree_host_impl.h" |
21 #include "cc/math_util.h" | 20 #include "cc/math_util.h" |
22 #include "cc/occlusion_tracker.h" | 21 #include "cc/occlusion_tracker.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 } | 139 } |
141 } | 140 } |
142 } | 141 } |
143 | 142 |
144 LayerTreeSettings::~LayerTreeSettings() | 143 LayerTreeSettings::~LayerTreeSettings() |
145 { | 144 { |
146 } | 145 } |
147 | 146 |
148 RendererCapabilities::RendererCapabilities() | 147 RendererCapabilities::RendererCapabilities() |
149 : bestTextureFormat(0) | 148 : bestTextureFormat(0) |
150 , contextHasCachedFrontBuffer(false) | |
151 , usingPartialSwap(false) | |
danakj
2012/12/06 06:12:27
oh that's not good.
| |
152 , usingAcceleratedPainting(false) | 149 , usingAcceleratedPainting(false) |
153 , usingSetVisibility(false) | 150 , usingSetVisibility(false) |
154 , usingSwapCompleteCallback(false) | 151 , usingSwapCompleteCallback(false) |
155 , usingGpuMemoryManager(false) | 152 , usingGpuMemoryManager(false) |
156 , usingDiscardFramebuffer(false) | 153 , usingDiscardFramebuffer(false) |
157 , usingEglImage(false) | 154 , usingEglImage(false) |
158 , allowPartialTextureUpdates(false) | 155 , allowPartialTextureUpdates(false) |
159 , maxTextureSize(0) | 156 , maxTextureSize(0) |
160 { | 157 { |
161 } | 158 } |
(...skipping 16 matching lines...) Expand all Loading... | |
178 } | 175 } |
179 | 176 |
180 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) | 177 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) |
181 : m_animating(false) | 178 : m_animating(false) |
182 , m_needsAnimateLayers(false) | 179 , m_needsAnimateLayers(false) |
183 , m_needsFullTreeSync(true) | 180 , m_needsFullTreeSync(true) |
184 , m_client(client) | 181 , m_client(client) |
185 , m_commitNumber(0) | 182 , m_commitNumber(0) |
186 , m_renderingStats() | 183 , m_renderingStats() |
187 , m_rendererInitialized(false) | 184 , m_rendererInitialized(false) |
188 , m_contextLost(false) | 185 , m_outputSurfaceLost(false) |
189 , m_numTimesRecreateShouldFail(0) | 186 , m_numTimesRecreateShouldFail(0) |
190 , m_numFailedRecreateAttempts(0) | 187 , m_numFailedRecreateAttempts(0) |
191 , m_settings(settings) | 188 , m_settings(settings) |
192 , m_debugState(settings.initialDebugState) | 189 , m_debugState(settings.initialDebugState) |
193 , m_deviceScaleFactor(1) | 190 , m_deviceScaleFactor(1) |
194 , m_visible(true) | 191 , m_visible(true) |
195 , m_pageScaleFactor(1) | 192 , m_pageScaleFactor(1) |
196 , m_minPageScaleFactor(1) | 193 , m_minPageScaleFactor(1) |
197 , m_maxPageScaleFactor(1) | 194 , m_maxPageScaleFactor(1) |
198 , m_triggerIdleUpdates(true) | 195 , m_triggerIdleUpdates(true) |
(...skipping 16 matching lines...) Expand all Loading... | |
215 { | 212 { |
216 return initializeProxy(proxyForTesting.Pass()); | 213 return initializeProxy(proxyForTesting.Pass()); |
217 } | 214 } |
218 | 215 |
219 bool LayerTreeHost::initializeProxy(scoped_ptr<Proxy> proxy) | 216 bool LayerTreeHost::initializeProxy(scoped_ptr<Proxy> proxy) |
220 { | 217 { |
221 TRACE_EVENT0("cc", "LayerTreeHost::initializeForReal"); | 218 TRACE_EVENT0("cc", "LayerTreeHost::initializeForReal"); |
222 | 219 |
223 m_proxy = proxy.Pass(); | 220 m_proxy = proxy.Pass(); |
224 m_proxy->start(); | 221 m_proxy->start(); |
225 return m_proxy->initializeContext(); | 222 return m_proxy->initializeOutputSurface(); |
226 } | 223 } |
227 | 224 |
228 LayerTreeHost::~LayerTreeHost() | 225 LayerTreeHost::~LayerTreeHost() |
229 { | 226 { |
230 if (m_rootLayer) | 227 if (m_rootLayer) |
231 m_rootLayer->setLayerTreeHost(0); | 228 m_rootLayer->setLayerTreeHost(0); |
232 DCHECK(m_proxy); | 229 DCHECK(m_proxy); |
233 DCHECK(m_proxy->isMainThread()); | 230 DCHECK(m_proxy->isMainThread()); |
234 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 231 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
235 m_proxy->stop(); | 232 m_proxy->stop(); |
236 numLayerTreeInstances--; | 233 numLayerTreeInstances--; |
237 RateLimiterMap::iterator it = m_rateLimiters.begin(); | 234 RateLimiterMap::iterator it = m_rateLimiters.begin(); |
238 if (it != m_rateLimiters.end()) | 235 if (it != m_rateLimiters.end()) |
239 it->second->stop(); | 236 it->second->stop(); |
240 } | 237 } |
241 | 238 |
242 void LayerTreeHost::setSurfaceReady() | 239 void LayerTreeHost::setSurfaceReady() |
243 { | 240 { |
244 m_proxy->setSurfaceReady(); | 241 m_proxy->setSurfaceReady(); |
245 } | 242 } |
246 | 243 |
247 void LayerTreeHost::initializeRenderer() | 244 void LayerTreeHost::initializeRenderer() |
248 { | 245 { |
249 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); | 246 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); |
250 if (!m_proxy->initializeRenderer()) { | 247 if (!m_proxy->initializeRenderer()) { |
251 // Uh oh, better tell the client that we can't do anything with this con text. | 248 // Uh oh, better tell the client that we can't do anything with this out put surface. |
252 m_client->didRecreateOutputSurface(false); | 249 m_client->didRecreateOutputSurface(false); |
253 return; | 250 return; |
254 } | 251 } |
255 | 252 |
256 // Update m_settings based on capabilities that we got back from the rendere r. | 253 // Update m_settings based on capabilities that we got back from the rendere r. |
257 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting; | 254 m_settings.acceleratePainting = m_proxy->rendererCapabilities().usingAcceler atedPainting; |
258 | 255 |
259 // Update m_settings based on partial update capability. | 256 // Update m_settings based on partial update capability. |
260 size_t maxPartialTextureUpdates = 0; | 257 size_t maxPartialTextureUpdates = 0; |
261 if (m_proxy->rendererCapabilities().allowPartialTextureUpdates) | 258 if (m_proxy->rendererCapabilities().allowPartialTextureUpdates) |
262 maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdates, m_pr oxy->maxPartialTextureUpdates()); | 259 maxPartialTextureUpdates = min(m_settings.maxPartialTextureUpdates, m_pr oxy->maxPartialTextureUpdates()); |
263 m_settings.maxPartialTextureUpdates = maxPartialTextureUpdates; | 260 m_settings.maxPartialTextureUpdates = maxPartialTextureUpdates; |
264 | 261 |
265 m_contentsTextureManager = PrioritizedResourceManager::create(Renderer::Cont entPool, m_proxy.get()); | 262 m_contentsTextureManager = PrioritizedResourceManager::create(Renderer::Cont entPool, m_proxy.get()); |
266 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(gfx::Si ze(), GL_RGBA); | 263 m_surfaceMemoryPlaceholder = m_contentsTextureManager->createTexture(gfx::Si ze(), GL_RGBA); |
267 | 264 |
268 m_rendererInitialized = true; | 265 m_rendererInitialized = true; |
269 | 266 |
270 m_settings.defaultTileSize = gfx::Size(min(m_settings.defaultTileSize.width( ), m_proxy->rendererCapabilities().maxTextureSize), | 267 m_settings.defaultTileSize = gfx::Size(min(m_settings.defaultTileSize.width( ), m_proxy->rendererCapabilities().maxTextureSize), |
271 min(m_settings.defaultTileSize.height (), m_proxy->rendererCapabilities().maxTextureSize)); | 268 min(m_settings.defaultTileSize.height (), m_proxy->rendererCapabilities().maxTextureSize)); |
272 m_settings.maxUntiledLayerSize = gfx::Size(min(m_settings.maxUntiledLayerSiz e.width(), m_proxy->rendererCapabilities().maxTextureSize), | 269 m_settings.maxUntiledLayerSize = gfx::Size(min(m_settings.maxUntiledLayerSiz e.width(), m_proxy->rendererCapabilities().maxTextureSize), |
273 min(m_settings.maxUntiledLayerSiz e.height(), m_proxy->rendererCapabilities().maxTextureSize)); | 270 min(m_settings.maxUntiledLayerSiz e.height(), m_proxy->rendererCapabilities().maxTextureSize)); |
274 } | 271 } |
275 | 272 |
276 LayerTreeHost::RecreateResult LayerTreeHost::recreateContext() | 273 LayerTreeHost::RecreateResult LayerTreeHost::recreateOutputSurface() |
277 { | 274 { |
278 TRACE_EVENT0("cc", "LayerTreeHost::recreateContext"); | 275 TRACE_EVENT0("cc", "LayerTreeHost::recreateOutputSurface"); |
279 DCHECK(m_contextLost); | 276 DCHECK(m_outputSurfaceLost); |
280 | 277 |
281 bool recreated = false; | 278 bool recreated = false; |
282 if (!m_numTimesRecreateShouldFail) | 279 if (!m_numTimesRecreateShouldFail) |
283 recreated = m_proxy->recreateContext(); | 280 recreated = m_proxy->recreateOutputSurface(); |
284 else | 281 else |
285 m_numTimesRecreateShouldFail--; | 282 m_numTimesRecreateShouldFail--; |
286 | 283 |
287 if (recreated) { | 284 if (recreated) { |
288 m_client->didRecreateOutputSurface(true); | 285 m_client->didRecreateOutputSurface(true); |
289 m_contextLost = false; | 286 m_outputSurfaceLost = false; |
290 return RecreateSucceeded; | 287 return RecreateSucceeded; |
291 } | 288 } |
292 | 289 |
293 // Tolerate a certain number of recreation failures to work around races | 290 // Tolerate a certain number of recreation failures to work around races |
294 // in the context-lost machinery. | 291 // in the output-surface-lost machinery. |
295 m_numFailedRecreateAttempts++; | 292 m_numFailedRecreateAttempts++; |
296 if (m_numFailedRecreateAttempts < 5) { | 293 if (m_numFailedRecreateAttempts < 5) { |
297 // FIXME: The single thread does not self-schedule context | 294 // FIXME: The single thread does not self-schedule output surface |
298 // recreation. So force another recreation attempt to happen by requesti ng | 295 // recreation. So force another recreation attempt to happen by requesti ng |
299 // another commit. | 296 // another commit. |
300 if (!m_proxy->hasImplThread()) | 297 if (!m_proxy->hasImplThread()) |
301 setNeedsCommit(); | 298 setNeedsCommit(); |
302 return RecreateFailedButTryAgain; | 299 return RecreateFailedButTryAgain; |
303 } | 300 } |
304 | 301 |
305 // We have tried too many times to recreate the context. Tell the host to fa ll | 302 // We have tried too many times to recreate the output surface. Tell the |
306 // back to software rendering. | 303 // host to fall back to software rendering. |
307 m_client->didRecreateOutputSurface(false); | 304 m_client->didRecreateOutputSurface(false); |
308 return RecreateFailedAndGaveUp; | 305 return RecreateFailedAndGaveUp; |
309 } | 306 } |
310 | 307 |
311 void LayerTreeHost::deleteContentsTexturesOnImplThread(ResourceProvider* resourc eProvider) | 308 void LayerTreeHost::deleteContentsTexturesOnImplThread(ResourceProvider* resourc eProvider) |
312 { | 309 { |
313 DCHECK(m_proxy->isImplThread()); | 310 DCHECK(m_proxy->isImplThread()); |
314 if (m_rendererInitialized) | 311 if (m_rendererInitialized) |
315 m_contentsTextureManager->clearAllMemory(resourceProvider); | 312 m_contentsTextureManager->clearAllMemory(resourceProvider); |
316 } | 313 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 m_hudLayer->removeFromParent(); | 419 m_hudLayer->removeFromParent(); |
423 m_hudLayer = 0; | 420 m_hudLayer = 0; |
424 } | 421 } |
425 } | 422 } |
426 | 423 |
427 void LayerTreeHost::commitComplete() | 424 void LayerTreeHost::commitComplete() |
428 { | 425 { |
429 m_client->didCommit(); | 426 m_client->didCommit(); |
430 } | 427 } |
431 | 428 |
432 scoped_ptr<GraphicsContext> LayerTreeHost::createContext() | 429 scoped_ptr<OutputSurface> LayerTreeHost::createOutputSurface() |
433 { | 430 { |
434 return m_client->createOutputSurface(); | 431 return m_client->createOutputSurface(); |
435 } | 432 } |
436 | 433 |
437 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() | 434 scoped_ptr<InputHandler> LayerTreeHost::createInputHandler() |
438 { | 435 { |
439 return m_client->createInputHandler(); | 436 return m_client->createInputHandler(); |
440 } | 437 } |
441 | 438 |
442 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client) | 439 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::createLayerTreeHostImpl(LayerTreeHo stImplClient* client) |
443 { | 440 { |
444 return LayerTreeHostImpl::create(m_settings, client, m_proxy.get()); | 441 return LayerTreeHostImpl::create(m_settings, client, m_proxy.get()); |
445 } | 442 } |
446 | 443 |
447 void LayerTreeHost::didLoseContext() | 444 void LayerTreeHost::didLoseOutputSurface() |
448 { | 445 { |
449 TRACE_EVENT0("cc", "LayerTreeHost::didLoseContext"); | 446 TRACE_EVENT0("cc", "LayerTreeHost::didLoseOutputSurface"); |
450 DCHECK(m_proxy->isMainThread()); | 447 DCHECK(m_proxy->isMainThread()); |
451 m_contextLost = true; | 448 m_outputSurfaceLost = true; |
452 m_numFailedRecreateAttempts = 0; | 449 m_numFailedRecreateAttempts = 0; |
453 setNeedsCommit(); | 450 setNeedsCommit(); |
454 } | 451 } |
455 | 452 |
456 bool LayerTreeHost::compositeAndReadback(void *pixels, const gfx::Rect& rect) | 453 bool LayerTreeHost::compositeAndReadback(void *pixels, const gfx::Rect& rect) |
457 { | 454 { |
458 m_triggerIdleUpdates = false; | 455 m_triggerIdleUpdates = false; |
459 bool ret = m_proxy->compositeAndReadback(pixels, rect); | 456 bool ret = m_proxy->compositeAndReadback(pixels, rect); |
460 m_triggerIdleUpdates = true; | 457 m_triggerIdleUpdates = true; |
461 return ret; | 458 return ret; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 return; | 586 return; |
590 m_visible = visible; | 587 m_visible = visible; |
591 m_proxy->setVisible(visible); | 588 m_proxy->setVisible(visible); |
592 } | 589 } |
593 | 590 |
594 void LayerTreeHost::startPageScaleAnimation(gfx::Vector2d targetOffset, bool use Anchor, float scale, base::TimeDelta duration) | 591 void LayerTreeHost::startPageScaleAnimation(gfx::Vector2d targetOffset, bool use Anchor, float scale, base::TimeDelta duration) |
595 { | 592 { |
596 m_proxy->startPageScaleAnimation(targetOffset, useAnchor, scale, duration); | 593 m_proxy->startPageScaleAnimation(targetOffset, useAnchor, scale, duration); |
597 } | 594 } |
598 | 595 |
599 void LayerTreeHost::loseContext(int numTimes) | 596 void LayerTreeHost::loseOutputSurface(int numTimes) |
600 { | 597 { |
601 TRACE_EVENT1("cc", "LayerTreeHost::loseCompositorContext", "numTimes", numTi mes); | 598 TRACE_EVENT1("cc", "LayerTreeHost::loseCompositorOutputSurface", "numTimes", numTimes); |
602 m_numTimesRecreateShouldFail = numTimes - 1; | 599 m_numTimesRecreateShouldFail = numTimes - 1; |
603 m_proxy->loseContext(); | 600 m_proxy->loseOutputSurface(); |
604 } | 601 } |
605 | 602 |
606 PrioritizedResourceManager* LayerTreeHost::contentsTextureManager() const | 603 PrioritizedResourceManager* LayerTreeHost::contentsTextureManager() const |
607 { | 604 { |
608 return m_contentsTextureManager.get(); | 605 return m_contentsTextureManager.get(); |
609 } | 606 } |
610 | 607 |
611 void LayerTreeHost::composite() | 608 void LayerTreeHost::composite() |
612 { | 609 { |
613 if (!m_proxy->hasImplThread()) | 610 if (!m_proxy->hasImplThread()) |
614 static_cast<SingleThreadProxy*>(m_proxy.get())->compositeImmediately(); | 611 static_cast<SingleThreadProxy*>(m_proxy.get())->compositeImmediately(); |
615 else | 612 else |
616 setNeedsCommit(); | 613 setNeedsCommit(); |
617 } | 614 } |
618 | 615 |
619 void LayerTreeHost::scheduleComposite() | 616 void LayerTreeHost::scheduleComposite() |
620 { | 617 { |
621 m_client->scheduleComposite(); | 618 m_client->scheduleComposite(); |
622 } | 619 } |
623 | 620 |
624 bool LayerTreeHost::initializeRendererIfNeeded() | 621 bool LayerTreeHost::initializeRendererIfNeeded() |
625 { | 622 { |
626 if (!m_rendererInitialized) { | 623 if (!m_rendererInitialized) { |
627 initializeRenderer(); | 624 initializeRenderer(); |
628 // If we couldn't initialize, then bail since we're returning to softwar e mode. | 625 // If we couldn't initialize, then bail since we're returning to softwar e mode. |
629 if (!m_rendererInitialized) | 626 if (!m_rendererInitialized) |
630 return false; | 627 return false; |
631 } | 628 } |
632 if (m_contextLost) { | 629 if (m_outputSurfaceLost) { |
633 if (recreateContext() != RecreateSucceeded) | 630 if (recreateOutputSurface() != RecreateSucceeded) |
634 return false; | 631 return false; |
635 } | 632 } |
636 return true; | 633 return true; |
637 } | 634 } |
638 | 635 |
639 void LayerTreeHost::updateLayers(ResourceUpdateQueue& queue, size_t memoryAlloca tionLimitBytes) | 636 void LayerTreeHost::updateLayers(ResourceUpdateQueue& queue, size_t memoryAlloca tionLimitBytes) |
640 { | 637 { |
641 DCHECK(m_rendererInitialized); | 638 DCHECK(m_rendererInitialized); |
642 | 639 |
643 if (!rootLayer()) | 640 if (!rootLayer()) |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 else | 973 else |
977 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 974 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
978 } | 975 } |
979 } | 976 } |
980 | 977 |
981 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 978 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
982 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 979 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
983 } | 980 } |
984 | 981 |
985 } // namespace cc | 982 } // namespace cc |
OLD | NEW |