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

Side by Side Diff: cc/layer_tree_host.cc

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

Powered by Google App Engine
This is Rietveld 408576698